Yii Framework Forum: [EXTENSION] Bootstrap - Yii Framework Forum

Jump to content

  • (44 Pages)
  • +
  • « First
  • 42
  • 43
  • 44
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION] Bootstrap Bringing together Yii and Twitter Bootstrap Rate Topic: ***** 21 Votes

#861 User is offline   A.Miguel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 12-October 11

Posted 12 May 2013 - 07:22 PM

Hi,

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
0

#862 User is offline   migueArgentina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 09-March 11

Posted 13 May 2013 - 09:21 AM

View Postcappadochian, on 12 May 2013 - 02:52 AM, said:

I suppose:
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.
0

#863 User is offline   cappadochian 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 02-January 11

Posted 13 May 2013 - 11:54 AM

View PostmigueArgentina, on 13 May 2013 - 09:21 AM, said:

That's a good one, cappadochian, but it never pass the first if statement (the $_POST). I'm lost with this.

That's weird. I think it's because your form is not connected to your model properly.
What do you have in your controller?
0

#864 User is offline   migueArgentina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 09-March 11

Posted 13 May 2013 - 01:24 PM

View Postcappadochian, on 13 May 2013 - 11:54 AM, said:

That's weird. I think it's because your form is not connected to your model properly.
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.
0

#865 User is offline   cappadochian 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 02-January 11

Posted 13 May 2013 - 01:33 PM

View PostmigueArgentina, 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.
0

#866 User is offline   zitter 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 137
  • Joined: 14-July 09

Posted 14 May 2013 - 11:55 AM

Hi, sometimes I need to choose if I want to show or not a TbButtonGroup. I mean *not* ButtonGroup items, just ButtonGroup. To do it's very simple, just add two lines of code in TbButtonGroup.php :

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;

[...]

0

#867 User is offline   migueArgentina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 09-March 11

Posted 14 May 2013 - 10:55 PM

View Postcappadochian, on 13 May 2013 - 01:33 PM, said:

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.


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().
0

#868 User is offline   cappadochian 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 98
  • Joined: 02-January 11

Posted 15 May 2013 - 02:22 PM

View PostmigueArgentina, on 14 May 2013 - 10:55 PM, said:

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().

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.
0

#869 User is offline   Deva 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 09-April 13
  • Location:Bangalore

Posted 16 May 2013 - 05:38 AM

Can i know how to get popbox to login for my application. i'm also using bootstrap extension. here is my main.php file of layout.

<$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),
),
),
),
));
?>
>
0

Share this topic:


  • (44 Pages)
  • +
  • « First
  • 42
  • 43
  • 44
  • You cannot start a new topic
  • You cannot reply to this topic

3 User(s) are reading this topic
0 members, 3 guests, 0 anonymous users