martes, 9 de agosto de 2016

Traer varios registros de la base de datos

$users = \Yii::$app->db ->createCommand('SELECT * FROM user;')
->queryAll();
After running this command, our $users variable will be populated  with an array of users:
Array
(
[0] => Array
(
[id] => 1
[email] => test@example.com
[password] => test123
[first_name] => test
[last_name] => user
[created_at] => 0
[updated_at] => 0
)
)

Traer un registro de la base de datos

$user = \Yii::$app->db ->createCommand('SELECT * FROM user WHERE id= 1;')
->queryOne();
The queryOne() method returns an array of data for a single element. In the event that no data is found, this method will return false :
Array
(
[id] => 1
[email] => test@example.com
[password] => test123
[first_name] => test
[last_name] => user
[created_at] => 0
[updated_at] => 0
)

Obtener contar un queryScalar

$count = \Yii::$app->db ->createCommand('SELECT COUNT(*) FROM user;')
->queryScalar();

jueves, 4 de agosto de 2016

validaciones que s epueden usar en yii2

https://github.com/yiisoft/yii2/blob/master/docs/guide/tutorial-core-validators.md


https://github.com/yiisoft/yii2/blob/master/docs/guide/input-validation.md

martes, 2 de agosto de 2016

campos ocultos en yii

hidden field with model and form:
<?php echo $form->hiddenField($model, 'name'); ?>
or without model
<?php echo CHtml::hiddenField('name' , 'value', array('id' => 'hiddenInput')); ?>

martes, 5 de julio de 2016

Instalar un app avanzada en yii2


$ sudo composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-iems

se ejecuta el comando init

:/var/www/html/yii-iems$ ./init
Yii Application Initialization Tool v1.0

Which environment do you want the application to be initialized in?

  [0] Development
  [1] Production

  Your choice [0-1, or "q" to quit] 0

  Initialize the application under 'Development' environment? [yes|no] yes


instalar imagemagick

sudo apt-get install imagemagick
sudo apt-get install php5-imagick