[EXTENSION] Bootstrap Bringing together Yii and Twitter Bootstrap
#861
Posted 12 May 2013 - 07:22 PM
Is it possible to add form elements without passing a CModel object?
Currently all bootstrap calls seems to be calling activeDropDownList() instead of dropDownList().
Thanks in advance
A.Miguel
#862
Posted 13 May 2013 - 09:21 AM
cappadochian, on 12 May 2013 - 02:52 AM, said:
if (isset($_POST['horizontalForm'])) {
$model->setAttributes($_POST['horizontalForm']);
if ($model->save()) {
if (Yii::app()->getRequest()->getIsAjaxRequest())
Yii::app()->end();
else
$this->redirect(array('admin'));
}
}
That's a good one, cappadochian, but it never pass the first if statement (the $_POST). I'm lost with this.
#864
Posted 13 May 2013 - 01:24 PM
cappadochian, on 13 May 2013 - 11:54 AM, said:
What do you have in your controller?
public function actionUpdateOwn(){
$user = substr(Yii::app()->request->getQueryString(),20); // I'll change this later
if($user == Yii::app()->user->id){
$model=$this->loadModel($user);
if(isset($_POST['updateEmailForm'])){ // Never passes from here
$model->setAttributes($_POST['updateEmailForm']);
if($model->save()){
if(Yii::app()->getRequest()->getIsAjaxRequest())
Yii::app()->end();
else
$this->redirect(array('updateOwn'));
}
}
$this->render('updateOwn',array(
'model'=>$model,
));
}
else
throw new CHttpException(403,'No puede modificar el perfil de otro usuario.');
}
public function actionUpdateEmail(){
$model=$this->loadModel(Yii::app()->user->id);
$this->performAjaxValidation($model);
if(isset($_POST['User']))
{
$model->attributes=$_POST['User'];
$user = User::model()->findByPk($model->id);
$model->userName = $user->userName;
$model->passwordNew = '';
$model->passwordNewRepeat = '';
if(md5($model->password) == $user->password)
if($model->save())
$this->redirect(array('view','id'=>$model->id));
else
echo '<br/><br/><h4>Clave incorrecta</h4>';
}
$this->render('updateOwn',array(
'model'=>$model,
));
}
Since it never pass that if statement, never enters to the actionUpdateEmail function.
I think the solution must be very simple, but I'm very new at Yii.
Thanks in advance.
#865
Posted 13 May 2013 - 01:33 PM
migueArgentina, on 13 May 2013 - 01:24 PM, said:
public function actionUpdateOwn(){
$user = substr(Yii::app()->request->getQueryString(),20); // I'll change this later
if($user == Yii::app()->user->id){
$model=$this->loadModel($user);
if(isset($_POST['updateEmailForm'])){ // Never passes from here
$model->setAttributes($_POST['updateEmailForm']);
if($model->save()){
if(Yii::app()->getRequest()->getIsAjaxRequest())
Yii::app()->end();
else
$this->redirect(array('updateOwn'));
}
}
$this->render('updateOwn',array(
'model'=>$model,
));
}
else
throw new CHttpException(403,'No puede modificar el perfil de otro usuario.');
}
public function actionUpdateEmail(){
$model=$this->loadModel(Yii::app()->user->id);
$this->performAjaxValidation($model);
if(isset($_POST['User']))
{
$model->attributes=$_POST['User'];
$user = User::model()->findByPk($model->id);
$model->userName = $user->userName;
$model->passwordNew = '';
$model->passwordNewRepeat = '';
if(md5($model->password) == $user->password)
if($model->save())
$this->redirect(array('view','id'=>$model->id));
else
echo '<br/><br/><h4>Clave incorrecta</h4>';
}
$this->render('updateOwn',array(
'model'=>$model,
));
}
Since it never pass that if statement, never enters to the actionUpdateEmail function.
I think the solution must be very simple, but I'm very new at Yii.
Thanks in advance.
I think this is the wrong part:
if(isset($_POST['updateEmailForm']))
you have to put the same name as the model. If you have a model named User, you have to handle it like this
if(isset($_POST['User']))
check the name of the post variable with firebug.
#866
Posted 14 May 2013 - 11:55 AM
After public $dropup = false add these lines
/** * @var boolean indicates whether if ButtonGroup shold be visible. Defaults to 'true' **/ public $visible = true;
then, in run() method add:
public function run()
{
if($this->visible === false) return;
[...]
#867
Posted 14 May 2013 - 10:55 PM
cappadochian, on 13 May 2013 - 01:33 PM, said:
if(isset($_POST['updateEmailForm']))
you have to put the same name as the model. If you have a model named User, you have to handle it like this
if(isset($_POST['User']))
check the name of the post variable with firebug.
Cappadochian, thanks for your help but I cannot solve my problem. If I change 'updateEmailForm' to 'User', it enters to the if statement but now:
How can I get the modified fields from updateEmailForm? In fact it never calls actionUpdateEmail().
#868
Posted 15 May 2013 - 02:22 PM
migueArgentina, on 14 May 2013 - 10:55 PM, said:
How can I get the modified fields from updateEmailForm? In fact it never calls actionUpdateEmail().
I see that you don't understand even the basics (however I'm also by far not an expert yet, but at least I understand the basics). I strongly recommend you to at first watch some youtube videos about OOP and MVC architecture regarding PHP.
For now, the point is, that if you see the form, it means you are inside the actionUpdateEmail() function.
If you hit the submit button, you enter the following IF statement:
if(isset($_POST['User'])) {...
because you are posting attributes (the filled form fields' values) for the model User.and this is the part, where you make the model's attributes' values equal to the values you have entered in the form:
$model->attributes = $_POST['User'];this is called massive assignment, you have to read about it.
professionals, please correct me if I'm wrong.
#869
Posted 16 May 2013 - 05:38 AM
<$this->widget('bootstrap.widgets.TbNavbar', array(
'brand'=>'<img src="../images/personalTrainer.png"/>',
'brandUrl' => bu(),
'collapse' => true,
'items'=>array(
array(
'class'=>'bootstrap.widgets.TbMenu',
'items'=>array(
array('label' => 'Home', 'url' => array('/site/index')),
array('label' => 'Login', 'url' => array('/user/create'), 'visible' => app()->user->isGuest),
array('label'=>'('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest),
),
),
),
));
?>
>

Help











