Yii

Create pagination in yii framework

梦想的初衷 提交于 2019-12-24 02:42:05
问题 I want to create pagination on my page without grid-view or model. This is my controller code:- $providers = Yii::app()->db->createCommand($query)->queryAll(); $count = Yii::app()->db->createCommand($query)->queryAll(); $dataProvider = new CSqlDataProvider($query, array( 'totalItemCount' => $count, 'pagination' => array( 'pageSize' => 10, ), )); and my view code is:- <?php $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'students-grid', 'dataProvider'=> $dataProvider, )); ?> But when

Yii Framework: Alias “application.extensions.langhandler.ElangHandler” is invalid. Make sure it points to an existing PHP file

空扰寡人 提交于 2019-12-24 02:34:09
问题 I have a site developed and is working fine on development machine (Mac OS X 10.7). However when I port it over to a Linux server I ran into error: Alias "application.extensions.langhandler.ElangHandler" is invalid. Make sure it points to an existing PHP file It supposedly is a permission problem according the below article: http://code.google.com/p/yii/issues/detail?id=3039 However, I checked and the protected/extensions folder and down all have 755 permission. I even tried t make them all

Yii Framework: AJAX form?

十年热恋 提交于 2019-12-24 02:25:22
问题 Ok, I need help with something that seems pretty straightforward but I just can't figure out. I have a page in Yii into which I'm trying to embed an AJAX form. Let's call the page A. The form takes in a single value, and needs to validate and store it into the DB if it's alright. So far, here's what I've figured out: The form is in a view _form.php, which contains a CActiveForm and an ajaxSubmitButton which looks like this: <?php echo CHtml::ajaxSubmitButton('submit', $this->createUrl('/site

Yii的常用URL和渲染方法

隐身守侯 提交于 2019-12-24 02:19:01
当前页面url Yii::app()->request->url; 跳转前一个页面url $this->redirect(Yii::app()->request->urlReferrer); 根目录URL Yii::app()->baseUrl 或 Yii::app()->request->baseUrl; 自定义URL $this->createUrl('post/read',array('id'=>100))或Yii::app()->createUrl(); 当前项目::Yii::getPathOfAlias('webroot'); 主机: Yii::app()->request->hostInfo http://127.0.0.1 项目首页 Yii::app()->homeUrl /blog/index.php 渲染视图 $this->render('view', array('attribute1'=>'value1','attribute2'=>'value2')); 创建小组件$this->beginWidget(string $className, array $properties=array ( ))      $this->endWidget(); 局部渲染 renderPartial('view', array('attribute1'=>'value1',

Remove the need to write index.php on Yii

☆樱花仙子☆ 提交于 2019-12-24 02:12:15
问题 I've setup Yii 1.1.x on my WAMP environment, it all works however I am still need to use index.php in the URL for the routing to work. Mod rewrite has been enabled in my WAMP config. Can anyone explain what I need to alter to allow me to run the app without having index.php in the URL itself? My Yii config is as follows: // uncomment the following to enable URLs in path-format urlManager'=>array( 'urlFormat'=>'path', 'rules'=>array( '<controller:\w+>/<id:\d+>'=>'<controller>/view', '

how to convert count(*) and group by queries to yii and fetch data from it

China☆狼群 提交于 2019-12-24 01:27:38
问题 I want to convert this query in yii SELECT count(*) AS cnt, date(dt) FROM tbl_log where status=2 GROUP BY date(dt) and fetch data from that. I try this command ( dt is datetime field): $criteria = new CDbCriteria(); $criteria->select = 'count(*) as cnt, date(dt)'; $criteria->group = 'date(dt)'; $criteria->condition = 'status= 2'; $visit_per_day = $this->findAll($criteria); but no data will fetch! wath can I do to get data? 回答1: Probably you see no data because you need assign data to model

Yii::app()->user->isAdmin() is not working properly in layout page

僤鯓⒐⒋嵵緔 提交于 2019-12-24 01:17:58
问题 in my layout page Cmenu visible fn Yii::app()->user->isAdmin() is not working properly when i use Yii::app()->user->isAdmin() in someother view it showing correct value but not working in layout. my code in protected/views/layouts/main.php <?php $this->widget('zii.widgets.CMenu',array( 'items'=>array( array('label'=>'Home', 'url'=>array('/site/index'),/*'visible'=>!Yii::app()->user->isGuest*/), array('label'=>'Master','url'=>array('/site/master'),'visible'=>Yii::app()->user->isAdmin()), array

How to add captcha in Yii-2 application?

断了今生、忘了曾经 提交于 2019-12-23 22:58:32
问题 I'm trying to add the captcha to the login form. My environment: Yii 2 php 5.4.45 TS IIS 10.0 Windows 10 In login.php , LoginForm.php and SiteController.php I added the following (shown only the relevant parts): backend\views\site\login.php: use yii\captcha\Captcha; ... <?= $form->field($model, 'captcha')->widget(Captcha::className()) ?> ... common\models\LoginForm.php: ... public $captcha; ... public function rules() { return [ ... [['username', 'password', 'captcha'], 'required'], ['captcha

Yii Joined table but not all selected data is retrieved

不问归期 提交于 2019-12-23 22:12:46
问题 I have the following criteria in my controller. $criteria = new CDbCriteria; $criteria->select = 't.*,b.*,c.*'; $criteria->join = "INNER JOIN tbl_patient_chair b ON b.patient = '0005' INNER JOIN tbl_chair c ON b.chair = c.Serial_No"; $criteria->condition = "t.client_id = '0005'"; $model = Patient::model()->findAll($criteria); $this->render('view', array( 'model' => $model )); Then in my view I am trying to retrieve all the selected data by doing: foreach ($model as $models) print_r($model);

Yii: HAS_MANY search

梦想的初衷 提交于 2019-12-23 22:07:35
问题 I have the following tables: user (id, cv_personal_data_id), cv_personal_data (id, firstname, surname, gender, address, ...), cv_laboral_exp (id, user_id, position, seniority,... ), cv_study (id, user_id, name, institution, average, ...), cv_language (id, user_id, language_name, writing_level, ...) In my User model I have defined the following relations: public function relations() { return array( 'cvLaboralExps' => array(self::HAS_MANY, 'CvLaboralExp', 'user_id'), 'cvLanguages' => array(self