FAQ Database Discussion Community


Use Yii CDbCriteria to get dates with a specific month

php,yii
Hi i'd like to know if there is anyway we can use CDbCriteria to get data based on dates with a specific month. Say i need all entries that were created in May, i have a column paid_on so when i select May(05), i need to get all entries xxxx-05-xx...

yii table sorter customize ajaxurl

php,ajax,yii,tablesorter
I have my code: ajaxUrl : '<?php echo Yii::app()->createUrl("abc/def");?>&page={page}&size={size}&{sortList:col}&{filterList:fcol} ', source : http://mottie.github.io/tablesorter/docs/example-pager-ajax.html and it did work, but then in yii manager url we clean the url format so, we remove index.php in url, so it didn't accept unnual $_GET anymore. My current code is: ajaxUrl : '<?php echo Yii::app()->createUrl("abc/def",array("page"=>"{page}"));?>',...

HTML Action ID get method

javascript,php,jquery,html,yii
This may already be a copy of another question but I cant find it. I have an action in my form: <form id="bug-form" action="/AST_14/Bugg.ly2/index.php/bug/update/" method="post"> Now the way my system works is the each of the "bugs" that need updating have there own bug id, Normally this would go onto...

Yii: Redirect in controller to external site in new tab

php,browser,yii,controller
Is it possible to redirect to an external url inside a Yii controller and open the new page in a new tab? $this->redirect("http://www.google.com"); This works fine, but opens in the same tab. Is there a way to open the url in a different tab? Thanks...

How to check that value exist in YII Session Variable

php,arrays,session,yii,session-variables
I am using yii and creating a cart, by using id of product i need to check that id already exists or not , but i use in_array and array_key_exists but unable to solve it Here is my code of controller public function actionCartupdateajax() { //start yii session $session =...

Yii Framework - Storing field from a different table into a model

php,yii,yii2
I need some help with the Yii 2.x framework. I have 2 tables, stuff and table, each with their own models, Stuff and Table. stuff and table share a key. stuff contains table_id which links to id in table. The stuff controller contains the following code to retrieve all fields...

Can someone explain how Yii minimizing assets is supposed to work on Heroku?

php,heroku,yii,yii2
I just got through getting the minification to work (How do I combine & minify JS and CSS for a Yii app on Heroku?) locally. However, it creates the all-1bc649be34b1e6afc9b2419687cde016.js file under web/assets/. Yii creates a .gitignore to ignore everything in that directory. None of the files will make it...

CSRF in a PHP/Yii project

php,security,yii,csrf
I have a yii (php) project and now I want to test, if it is safe against csrf attacks. The code looks like this: if (!Yii::app()->request->isAjaxRequest)){ die("error"); } else { // Do stuff } Now, if I call the URL in Firebug, It works ("Do stuff" is executed). $.get("example.com/foo", function(data){...

PHP YII2 set session group_concat_max_len

php,yii
$model = Item::find() ->select('group_concat(item.ID) AS ItemID') ->joinWith('image', true, 'LEFT JOIN') ->where('item.user_id = :id', [':id' => Yii::$app->user->identity->ID]) ->all(); You see, if I do like this it will print me the string of itemID with 145 elements separated by comma, but if there are 3000k records in db, so it will output...

Yii reload page after CGridview Delete

php,ajax,yii
OK, this is frustrating. All I simply want to do is reload the page after a CGridView Delete action. As the Delete is performed VIA Ajax, I cannot seem to reload the page. I need to do this as I have other data on the page that is dependant on...

In Yii, how do you validate uniqueness against another column in the table?

php,yii,yii-modules,yii-validation
I am giving my users the ability to change their account email. To do so, when they submit the new email that they would like to switch to, I am storing that email in my database as a temporary email. Once the user clicks on the confirmation email sent to...

Yii won't load a model

php,model-view-controller,yii
I am unable to load a model in my NewController. In other controllers I can perfectly call this line: $vid = Video::model()->findByPk($id); and it will get me the right model. However in this controller: NewController.php it doesn't work. public function actionUpdate($id) { $model=$this->loadModel($id); $vid = Video::model()->findByPk($id); if(isset($vid)) // Check if...

Edit action in Yii framework

php,ajax,yii
I am working on a web application that allow users to have video conferences. Users are allowed to create video conferences and I want them to be able to also edit the scheduled video conferences but I am having trouble implementing that. Please help. Edit button in index.php view $html...

Strange error #32 on website's bottom using yii2

php,yii,yii2,shared-hosting
I am using yii2 , and I have recently uploaded my whole website on the godaddy shared server. I have uploaded on the root folder my all other folders like controller , vendors , config etc Then I have uploaded my "web" folder files like index.php and themes etc to...

can we remove default layout of view in yii 1.1

php,yii
I am new in yii, and trying to import a existing PHP site into this framework, so i want to remove default layout style of yii, just wanna show my view page. Is there any way to do so? like, when i load a view $this->render('myview'); then only myview.php should...

how to put confirm alert in controller and redirect to perticular link if cancel it in yii

javascript,php,yii
i want to put confirm alert in controller and redirect to perticular link if cancel button clicked. My admin.php code is: array( 'header' => 'Action', 'class' => 'CButtonColumn', 'template' => '{update}', 'updateButtonUrl' => 'Yii::app()->createUrl("attendance/inout", array("id"=>$data->supplier_master_id))' ) Here i have to put confirm alert in controller because some extra condition also...

yii 2.0 on ajax submit error Class 'app\controllers\ActiveForm' not found

php,ajax,yii,active-form
I have the following error Class 'app\controllers\ActiveForm' not found when submit the following ActiveForm (kartik\widgets\ActiveForm) $form = ActiveForm::begin([ 'type'=>ActiveForm::TYPE_VERTICAL, 'action' => 'incarico/update/'.$model->id, 'enableAjaxValidation' => true, 'enableClientValidation' => false, ]); My controller has this action: public function actionUpdate($id) { $model = $this->findModel($id); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {...

Yii2 subquery in Active Record

yii,yii2
How can I convert this sql into active record query SELECT * FROM `base_twitter` WHERE id NOT IN (SELECT base_id from base_followers) ...

Run string as static class function in Yii2

php,yii,yii2
I'm receiving prepared function as strings like these: "\app\models\AddrModel::getText('A_00001724');" Now I need to convert and run this string as static function call, to retrieve the value if the A_00001724 id. How do I do that? PS: When I call it as $value = new $function; I get Class '\app\models\AddrModel::getText('A_00001724')' not...

Yii 1: UrlManager does not call the correct action in module controller

yii,yii-url-manager
i am creating an API module in an application and i have to set some rules in urlManager, however when i set a single rule and test it if it's working, it calls the index action instead of the desired action. in Controller <?php Class ProjectsController extends Controller { //...

Yii2 Loading Page/Image when Bootstrap Modal is still Loading

php,jquery,twitter-bootstrap,yii,yii2
I have this modal: <?php echo Html::button( 'Create New Staff', [ 'value' => Url::to(['create-new-staff']), 'class' => 'btn btn-success btn-create', 'id' => 'modalButton' ]); Modal::begin(['id' => 'modal']); echo "<div id='modalContent'></div>"; Modal::end(); ?> Here's my sample loading indicator image: <img src="http://dkclasses.com/images/loading.gif" id="loading-indicator" style="display:none" /> When I click the modal button, I want...

yii cgridview displays summaryt text twice

php,yii
In my new yii application it displays as, Displaying 1-3 of 1 result.|Displaying 1-3 of 3 results. <div class="summary">Displaying 1-3 of 1 result.|Displaying 1-3 of 3 results.</div> i have no clue how this part is replicated, this is my code. <?php $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'data-grid', 'dataProvider'=>$model->search(), 'filter'=>$model, 'columns'=>array( array( 'name' =>...

Yii migration extend custom class

php,yii,migration
class m150602_071107_naujassss extends CDbMigration { public function up() { } public function down() { echo "m150602_071107_tests does not support migration down.\n"; return false; } /* // Use safeUp/safeDown to do migration with transaction public function safeUp() { } public function safeDown() { } */ } CDbMigration is default class to...

Changing pattern of url to accept username like facebook

php,regex,yii,yii-url-manager
I need to covert user profile link from this http://example.com/site/index?user_id=sami.yaqoub To be like Facebook http://example.com/sami.yaqoub I changed the rules of config file to except that. Config.php <?php .. 'urlManager' => array( 'urlFormat' => 'path', 'showScriptName' => false, 'rules' => array( '<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', '<controller:\w+>/<action:\w+>' =>...

Multiple db connections in Yii PHP framework

php,yii
This is the main.php file: 'db' => array( 'connectionString' => 'mysql:host=MYHOST;dbname=MYDB', 'emulatePrepare' => true, 'username' => 'MYUSER', 'password' => 'MYPASS', 'charset' => 'utf8', ), 'dbanother' => array( 'connectionString' => 'mysql:host=MYHOST;dbname=MYDB2', 'emulatePrepare' => true, 'username' => 'MYUSER2', 'password' => 'MYPASS2', 'charset' => 'utf8', 'class' => 'CDbConnection' ), In the UserIdentity from...

Yii2 db; dsn with ip local

php,database,yii,yii2
i have my localhost configured with and other port, i'm trying to use this in the 'yii\db\Connection' 'dsn' => 'mysql:host=192.168.1.5;dbname=db_empresa_juridico', 'username' => 'db_user_jurid', 'password' => '[removed]', 'charset' => 'utf8', but Yii2 still loading, don't show nothing how i can connecting to the db? using local ip? i need to shared...

Use Faker to fill table without knowing table structure

mysql,yii,yii2
Can I use (and if yes -- then how) Yii2 Faker to fill entire table (all columns) with random data for n records without knowing table structure? Can Faker check schema and do this for me or do I have to write my own code, that will use it in...

Using Gii afer updating model files

yii,yii2,gii
I am learning Yii and I wonder if I generate model and CRUD files using Gii and then I modified these files manually then I changed my database should I run Gii again ? is it going to overwrite my changes in the model files ? if so what is...

Yii, querying gives array to string error

php,yii
$paymentIDs = Yii::app()->db->createCommand('SELECT payment_id FROM client_package WHERE package_id = :pid AND payment_id IS NOT NULL')->bindValue(':pid', $pid)->queryAll(); $total = Yii::app()->db->createCommand('SELECT count(*) FROM payment WHERE id IN ('.implode(",", $paymentIDs).') AND date BETWEEN \':mS\' AND \':mE\'')->bindValue(':mS', $monthStart)->bindValue(':mE', $monthEnd)->queryScalar(); The above is my code for a query. As you can see, I queried for...

Advanced Search cannot clicked yii

php,jquery,yii
I have problem with my YII based application, in controller/admin there are link Advanced Search, if I click it must be show the form to search model. But when I click the link, nothing happened, I don't know why. I Also use CJuiDatePicker in my form. when I click the...

Unable to create table in MySql in Yii installation [closed]

php,mysql,yii
I am currently installing Yii framework using composer. There is step in which I have to create table in MySQL. They provided query for that: CREATE TABLE tbl_user ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, username VARCHAR(128) NOT NULL, password VARCHAR(128) NOT NULL, email VARCHAR(128) NOT NULL ); But...

How to check if any of the fields of a model are null or empty?

php,sql,yii,model
I have a model, $userModel. I want to check if any of the fields for this model are empty or null. At the moment I am doing it with a big if statement. if(!empty($userModel->name) && !empty($userModel->address) ... && !empty($userModel->email)) { // All fields have values } This way works, but...

How do I ignore PHP Notice: json_decode(): integer overflow detected in Yii?

php,json,yii,yii2
I'm trying to decode a long integer in JSON, but it always crashes and gives an error in Yii. I already use the JSON_BIGINT_AS_STRING option. How do I bypass this error or ignore it? php > var_dump( json_decode('[66933258,"B009GQ034C",281441845828]', false, 512, JSON_BIGINT_AS_STRING)); PHP Notice: json_decode(): integer overflow detected in php shell...

SET NOCOUNT ON is not working under ubuntu

php,sql-server,stored-procedures,yii
I am using mssqlserver with yii framework I have created one stored-procedure please see below code. //Call Store procedure to get data $sql = "EXECUTE IESReportData @assessmentId=:assessmentId, @queId=:queId,@instanceId=:instanceId"; //set database connection and start the yii query builder to be executed. $connection = Yii::app()->db; $command = $connection->createCommand($sql); $command->bindValue(":assessmentId", $assessmentId); $command->bindValue(":queId", "");...

how to put datepicker in controller in yii

php,jquery,ajax,yii,datepicker
I have a form in yii and one field in form is come from controller by clicking on a button. if i pass text field instead of datepicker then it works otherwise it gives error so what to do now? my form code is as below: <div class="row buttonproduct" hidden>...

Yii 1. Get products from categories AND their subcategories [Unlimited nesting]

php,recursion,yii,tree,catalog
I'm working on some catalog based project, which contains unlimited nesting (in reality, the maximum level would be 3, I guess, but it have to be dynamic anyways). Let me show what is done: OrganizationCategory model: public function relations() { return array( 'organizations' => array(self::HAS_MANY, 'Organization', 'organization_category_id'), 'parent' => array(self::BELONGS_TO,...

Yii widget reload via ajax

php,ajax,yii,yii-widgets
I need to reload a content of my Yii widget via AJAX every XX seconds. This is my widget code: class UserOnlineWidget extends CWidget { public function init(){ } public function run(){ $userOnline=User::getOnlineUser(); $this->render("userOnLineWidget", array('userOnline'=>$userOnline)); } } And this is the view userOnLineWidget.php: <div class="userOnline"> <h5>User Online</h5> <ul> <?php foreach($userOnline...

preg_match_all error when pattern is a variable in YII

php,yii
I have a table called dictionary, in which has words that want to find in a text being pulled from another table. I'm using preg_match_all to match the words in the text. I have tried many different solutions that found online, but no luck so far. It seems that the...

simple routing in yii framework 1

yii,routing
I am new to yii framework.I have a page controller and contact_us action then url become is site_url/page/contact_us but i want to it should be site_url/contact_us. i want to know how to set route for this and in which file. class PageController extends SiteController { function actionContact_us() { //something ;...

Property “CHasOneRelation.limit” is not defined

php,database,yii
How to get rid of this error: Property "CHasOneRelation.limit" is not defined. here is my relation method: public function relations() { return array( 'documents' => array(self::HAS_MANY, 'Document', 'dossier_id',), 'lastLogline' => array( self::HAS_ONE, 'Logline ll', 'dossier_id', 'limit' => 1, 'order' => 'll.create_date DESC'), 'lastmodifiedUser' => array(self::HAS_ONE, 'User', 'lastmodified_user_id',), 'loglines' => array(self::HAS_MANY,...

Send SMS of more than 160 characters in Php using Twilio

php,yii,twilio-php
I have used twilio yii extention. http://www.yiiframework.com/extension/twiliosms/ but can't send over than 160 characters message. it will generate this error. The message body exceeds the 160 character limit. [*:status] => 400 [*:info] => 'https://www.twilio.com/docs/errors/21605' [*:message] => 'The message body exceeds the 160 character limit.' [Exception:string] => '' [*:code] => 21605...

get_class() expects parameter 1 to be object, string given when using bitly-url-shortener [closed]

php,html,yii
I wanted to use bitly-url-shortener (http://www.yiiframework.com/extension/bitly-url-shortener/) to shorten my url. The code that I am using is below, <?php Yii::app()->bitly->shorten('http://www.betaworks.com')->getResponseData(); ?> It give me this error, get_class() expects parameter 1 to be object, string given D:\_App\buddyshop\protected\extensions\bitly\VGBitly.php(578) 566 */ 567 public function getErrorMessage() 568 { 569 return $this->errorMessage; 570 } 571...

Yii 1.x how to change model name in POST (CActiveForm)

yii
Its posible change model name in post/get? I have model with large names, like "VerLargeModelName" and many parameters. It does not fit in GET (query string limit). Update: i need just change generated inputs from CActiveForm (change LongModelName[a] to short[a])...

How to add link to a static page in Yii framework in routing rules?

php,yii
i hav my routing rules as 'components'=>array( /*'urlManager'=>array( 'urlFormat'=>'path', ),*/ 'urlManager'=>array( 'urlFormat'=>'path', 'rules'=>array( '<controller:\w+>/<id:\d+>'=>'<controller>/view', '<controller:\w+>'=>'<controller>/index', '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>' ) now i want to hav a img inside my page...

YII - Why to use beforeSave() when you can code before Save() function

php,yii,save,before-save
I am aware of functionality of function beforeSave() in YII that this function is used to perform something which we want to perform before our data saved. However, as far as we want to implement this before our data got save to database, can't we directly write this code before...

how to get data from other tables in grid view in yii

php,yii
I have a module named attendance but value in it is comes from other tables with some conditions. so how can i get id of other tables. my code is like below: models are: if($type == 2) { $model = new Supplier(); } elseif($type==3) { $model = new TruckingCompany(); }...

2amigos Daterangepicker is not working in Yii2

php,gridview,yii,yii2
I need to filter my records in GridView by date range, for example: 01-05-2015 to 09-05-2015. I am trying to use DateRangePicker from this extension for this, but it`s not working: <?= $form->field($model, 'created_at')->widget(DateRangePicker::className(), [ 'attributeTo' => 'date_to', 'model' => $model, // best for correct client validation 'language' => 'en',...

Yii 1.1.3 setting selected value of dependent dropdown

php,yii
I have 3 dependent dropdowns on my page for creation of entity. echo CHtml::dropDownList('OpenLessons[Building]', '', $buildingList,array( 'ajax' => array( 'type'=>'POST', 'url'=>CController::createUrl('ajax/floorList'), //url to call. 'update'=>'#OpenLessons_Floor', //selector to update ))); echo CHtml::dropDownList('OpenLessons[Floor]','', array(),array( 'ajax' => array( 'type'=>'POST', 'url'=>CController::createUrl('ajax/roomList'), 'update'=>'#OpenLessons_Class_ID', ))); echo...

How to load selected values in multiple-dropdown in update view in yii?

php,mysql,yii
I am new in yii. I have problem with fetching selected values in dropdown when updating the record. I have dropdown with multiple selection of user's email. When adding it is working fine, it allows me to select multiple values and can insert selected value's ids comma separated in database....

Yii::app()->clientScript->registerCoreScript('jquery');

javascript,jquery,yii
I am using <?php Yii::app()->clientScript->registerCoreScript('jquery'); ?> for register jquery in Yii 1 top of script but in page added last of scripts? why?...

PHP: Is there a relationship between PDO transactions and Sessions?

php,yii,pdo,transactions,session-variables
I am currently working on a project to uses Yii and stumbled across something that made me scratch my head. I started a db transaction using Yii (which just calls PDO::beginTransaction) and did some database stuff and at the end, store a flash message for the user and do a...

run some script when session end in Yii 1

php,session,yii
My session configuration in config file (main.php) is: 'session' => array( 'class' => 'CDbHttpSession', 'timeout' => 60*60, // 1 hour ), And I put this code in layout file: <?php if (!Yii::app()->user->isGuest) { ?> <meta http-equiv="refresh" content="<?php echo Yii::app()->params['session_timeout'];?>;"/> <?php } ?> So far, there are no announcement when the...

TABLE.label doesnt exist YII, framework

php,database,database-design,yii,localhost
I was working with YII framework, I made the models and then I used the Crud generator and I also made those things using Crud generator. Everything works fine so when I go to localHost/myprogram/index.php/myTable I can see the table myTable. I have 6 tables in my Database and they...

MongoDB on Amazon EC2 - Configuring Mongo Client for Php

php,mongodb,yii,amazon-ec2,yii2
I am pretty new to Amazon EC2. I followed the instructions given in mongodb official site for installing mongodb on Amazon Linux. I have a Yii-2(basic) project to host on my amazon Linux server. mongoDB is already installed in the and even I Imported some dumps over there. But when...

Grab all users from Database that meet two conditions

php,sql,yii
I am trying to get all users who are type usertype 1 or usertype 3. I think I can do it using a join, but I would like something without join. Here is what I am trying: $users = User::model()->findAllBySql("SELECT * FROM user WHERE (usertype = 3 and usertype =...

PHP - Yii - dynamic properties CActiveRecord

php,yii
I have class Person which have properties {property}_{countrycode}. This class can have 20 properties and each property with country code. 20x3 = 60 properties defined in class. With each language I need to define them manually in class. class Person extends CActiveRecord { public $name_sk; public $name_cz; public $name_de; public...

Yii - multiple databases with one user authentication

yii
I am facing a problem trying to develop an application in Yii (v=1.1). Client wants the application to has multiple databases (one per his customer). That means that we will have unknown number of databases. Also He wants to have only one user authentication system - regard of it, users...

Setting ID attribute of input field when using ActiveField in Yii2?

yii,yii2
I'm trying to set a custom id for an input field whilst using ActiveField in Yii2. I tried the below, but it instead set the id of the field container instead of the input field itself. $form->field($model, 'some_id', ['options' => ['id' => 'some_id']])->hiddenInput(['value' => $some_id])->label(false); Is there a way I...

Organize your code when build search with Yii 1.1.15

php,optimization,yii,code-quality
Actually its not about code writing, its about proper organize code. Hello, I want to build search for my webapplication, and I have the few question what a little bit confuse me. So the first issue: I need to create separate action for search data by params and return response...

Working with memcache with Yii and ActiveRecords

php,yii,memcached,yii2
So I've been trying to get memcache working on my site running Yii 2. I've got the caching working for the DB schema stuff, but it doesn't seem to work for ActiveRecord queries. This is my config for the DB: 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=127.0.0.1;dbname=db_name', 'username'...

Preventing user from viewing another user profile in Yii

php,yii
I have some question about my app. How can I prevent a user from viewing another user profile? I mean, a user can only view their own profile. If user 123 is logged in, he is allowed in 'view&id=123' but denied in 'view&id=234' etc. I know how to do this...

Creating a Revision History in Yii

php,yii
I am using Yii. I currently have it set up so I can overwrite data which belongs to bug_id. But I would like to save this data to another model(History) under history_id and once you edit the bug it does not change the data saved in the history table. The...

Query in Yii - Adding Condition

php,sql,yii
I want to add a condition to my query, which will remove the product_id that is equal to 999. Currently, I get the following error: Property "CDbCriteria.where" is not defined. Any suggestions? Query in my PHP Controller $products = Product::model()->findAll(array( "condition" => $condition, "where" => 'product_id != 999', 'order' =>...

Clone Yii project from git

php,git,yii
We are developing a Yii web app and after setting up it in a local laptop we pushed the project into a git repository (without the vendor directory). Now I'd like to pull it in another local machine, but when I try to do that of course the vendor dir...

Yii2 - check if the user is logged in view

yii,yii2
I am trying to check is the user logged inside my view file, but I keep getting this error: Call to undefined method Yii::app() I tried adding $ before app but the error is still there (this time it is Undefined variable: app). Is it possible to this is view?...

Yii2 route using yii\rest\UrlRule with several parameters

php,rest,yii,routing,yii2
I am trying to use Yii 2 routing for REST API. Following tutorial at http://www.yiiframework.com/doc-2.0/guide-rest-routing.html, I have already defined (with success) a lot of rule for API entry point like so : 'urlManager' => [ 'enablePrettyUrl' => true, 'enableStrictParsing' => true, 'showScriptName' => false, 'rules' => [ [ 'class' =>...

Yii1 - HtmlPurifier removes allowfullscreen attribute

php,regex,iframe,yii,htmlpurifier
I am using below configuration to clean the input from user in my Yii project using its inbuilt support for HtmlPurifier array( 'URI.AllowedSchemes' => array( 'http' => true, 'https' => true, ), "HTML.SafeEmbed" => true, 'HTML.TargetBlank' => true, "HTML.SafeIframe" => true, "Filter.YouTube" => true, 'URI.SafeIframeRegexp' => '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%' ), Example:- <iframe...

I want to hit url of another application in a yii framework application.How to do that?

php,url,yii
I want to hit url of another application in a yii framework application.How to do that? I can do it in my own app like this: <tr> <td> <?php echo CHtml::link('Agent', $this->createUrl('/agent/agent/admin')); ?> </td> </tr> But I want to hit some url outside by application. How to do that?...

How to check whether the user is already logged in on different ip/locations

php,mysql,yii
I want to check whether the same user is logged in more than one locations over different IP and if a user already logged in then the previous session will be destroyed. Is there any solution on YII framework? Currently I am trying to develop this project on YII framework....

Yii console app - Class 'Guzzle\Http\Client' not found

web-applications,yii,console-application,guzzle
My configs: /trunk/common/extensions/Api/Api.php /trunk/vendor/guzzle webapp config: /trunk/members/config/main.php ... 'components' => array( 'api' => array( 'class' => 'common.extensions.Api.Api' ) ... ) ... console config: /trunk/console/config/main.php ... 'components' => array( 'api' => array( 'class' => 'common.extensions.Api.Api' ) ... ) ... Client.php namespace Guzzle\Http; Guzzle was installed via composer. When I run the...

Yii2 : How to validate XSS (Cross Site Scripting) in form / model input?

validation,activerecord,yii,xss,yii2
Yii2 has support for XSS(cross-site-scripting ) validation of displayed data using the helper class\yii\helpers\HtmlPurifier, however this only validates and cleans up output code like this echo HtmlPurifier::process($html); How to validate input for XSS of input such that this data is not stored in the database itself ?...

How to use Delay for method execution in jquery

javascript,jquery,yii
I am using jquery in my one of the form. where on click of submit button i call one function QuoteDetailValidation(). In which i validate fields. But after validate that fields i try to get all fields which have errorActive class. But unfortunately i can't get it. See my code...

Unique value rule for an attribute in yii

php,yii,unique
I'm new to yii. I have a table called 'member' and when entering values to that through my yii app, the user should not be allowed to insert a member with same NIC. Is there a default rule for that or should I create a custom rule? Can any one...

URL routing rules in Yii2

php,yii,yii-routing
Coming from background of Laravel and Rails I am finding quite a difficulty to figure out how Yii2 rules work. I am looking for following URL patterns: /articles/ /articles/view/ /articles/1/my-pretty-article ArticlesController is defined like: <?php namespace app\controllers; class ArticlesController extends \yii\web\Controller { public function actionIndex() { return $this->render('index'); } public...

Yii2 - Multi language

php,yii,yii2-advanced-app
I'm trying to set up the website's frontend translation using the i18l thing. Here is my i18l.php file placed on frontend/config <?php return [ 'sourcePath' => 'frontend', 'languages' => ['en-US', 'pt-BR'] , //Add languages to the array for the language files to be generated. 'translator' => 'Yii::t', 'sort' => false,...

How to show uploaded image in view page? I am new in yii, I am unable to fix this please help me

yii
In myprofile.php <?php echo CHtml::image(Yii::app()->request- >baseUrl.'/xampp/htdocs/myapp/images/'.$model- >image,"image",array("width"=>200,"hieght"=>200)); ?> ...

Lime Survey after user logged in with his token to participate in survey, a separate session is maintained for users?

php,yii,yii2,limesurvey
After User logged in with his token to participate in the survey. A separate logged in session is created in the lime survey application ?? If so where the session is set in the source code of lime survey. I need to keep the survey in save/edit mode. so that...

Yii - Calling api request within CConsole

api,yii,console,command
I have the following issue: I have a local db with comments and I need to do some actions with some users I'm getting via an API request. Code is something like this: class RunCronCommand extends CConsoleCommand { public function actionIndex() { ... $comments = Comment::model()->findAll('status = :status', array(':status' =>...

Custom Widget in Yii

php,yii,view,widget
I create new widget like this: class MyMenu extends CWidget { public function init() { } public function run() { $Items = array( array('label'=>'Home', 'url'=>array('/site/index')), array('label'=>'Add User', 'url'=>array('/user/register')), array('label'=>'View Users', 'url'=>array('/user/index')), array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest), array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'),...

How to get all ActiveRecord objects in Yii2?

php,yii,yii2
How can I get all ActiveRecord objects in Yii2 like an array, which can be iterated by foreach() . This is the code which should work but it returns zeros instead of actual data. public function getAllCategories(){ $categoriesList=[]; $categories= Category::find()->orderBy("id")->all(); foreach ($categories as $category){ $categoriesList[]+=$category->title; } return $categoriesList; } ...

Yii get current logged user

php,yii
To get current user I use Yii::app()->user->name it's ok when I'm logged as a user. But when cron job executin command and try Yii::app()->user->name it's get Property "CConsoleApplication.user" is not defined.. How to get check inside my method does Yii::app() user os defined I'm try use isset() but still getting...

Yii2 - JSONP response returns nothing (blank) and does not work, but JSON does

php,json,yii,jsonp,yii2
I am using Yii2, and for what it's worth, I know the basics, and have been programming for a while. This is probably from a lack of documentation in this area (Yii2 JSONP and Responses). All I find is examples of returning a JSON response, none showing a JSONP response....

Yii internal redirect

php,yii
I'm using a yii framework for a website. My apache rewrite all request to the yii application. In my default controller I check every request and if there is content in database available a webpage will be displayed. When there is no content available I dispay a custom 404 error...

Yii behaviors won't save data

php,yii,many-to-many,behavior
I'm trying to save relations in third table 'Relations'. Here's code: Controller save action: $relations = $_POST['VideoCaptions']['countries']; $model->attachBehavior('ManyToManyRelationBehavior', array( 'class' => 'ManyToManyRelationBehavior', 'modelNameRelation' => 'Relations', 'firstField' => 'video_captions', 'secondField' => 'video_countries', 'relationList' => $relations, )); ManyToManyRelationBehavior class afterSave action: if (is_array($this->relationList)){ $model_ = $this->modelNameRelation;...

Yii2: get raw sql of model->save()

php,activerecord,yii,yii2
I want to add record to a table with ActiveRecord. Here is my code: $model = new Article(); $model->title = 'test title'; $model->content = 'test content'; $model->category_id = 1; $model->author_id = 1; if ($model->validate()) { $model->save(); } $model->validate() returns true, but $model->save() returns false. How to find generated raw sql...

How to properly create different logins for different Modules in Yii framework

php,yii,yii-components
In my Yii 1.x application I defined new Admin module. In the init method of the admin module I defined new user component like this: $this->setComponents(array( 'user'=>array( 'class' => 'CWebUser', // enable cookie-based authentication 'allowAutoLogin'=>true, 'baseUrl'=>Yii::app()->createUrl("admin/user/login"), 'stateKeyPrefix' => '_admin', ), )); Now, I expect I can do the following: Yii::app()->getModule("admin")->user->login($this->_identity,$duration)...

Invalid Request YII when delete model via POST

yii
I want delete my model via post , but I always get Invalid Request this is my view <?php echo CHtml::link(CHtml::encode('Delete image'), array('gambar/delete', 'id' => $data->id), array( 'submit' => array('data/delete', 'id' => $data->id), 'class' => 'delete', 'confirm' => 'This will remove the image. Are you sure?' ) ); ?> and...

How to increment number of fields in php using javascript or jquery or ajax without reload whole page

javascript,php,jquery,ajax,yii
I have a form in yii and there is a text field named certificate_name in it. Now i want that when I click on the plus icon, the text field should increment by one and appear below the previous field. Here is my php code: <?php for ($i = 0;...

Filter data in Yii framework issue?

php,search,yii,filter
This is the view : <?php $this->renderPartial('_search', array( 'model' => $model )); ?> This is the _search.php file: <div class="wide form"> <?php $form = $this->beginWidget('CActiveForm', array( 'action' => Yii::app()->createUrl($this->route), 'method'=>'get', )); ?> <div class="row"> <?php echo $form->label($model,'month'); ?> <?php echo $form->textField($model,'month'); ?> </div> <div class="row"> <?php echo $form->label($model,'year'); ?> <?php...

how to allow text attributes to be empty in Yii model?

validation,yii,model
I have a model for articles, the article can be written in two languages, English and Arabic. So there are 2 attributes for each language text, I want the both attributes to be allowed to be empty on create and update, knowing that the attributes type are text not varchar....

Yii criteria - modify to include OR Condition

mysql,yii,yii-components
I have the following line of code that does a simple query if ($this->fulfilled) $criteria->addCondition('fulfilled ' . (($this->fulfilled == 1) ? "IS NOT NULL" : "IS NULL")); How can modify this to do a query that contains an OR command to basically run this query using the framework rather than...

CDbConnection failed to open the DB connection: unable to open database file

php,mysql,yii
I am trying to use the gii code generator to create models. I was able to access the gii code generator on my browser. However, when I click on the 'Model Genetator' I get the CDbException which says this 'DbConnection failed to open the DB connection: SQLSTATE[HY000] [14] unable to...

Config Yii::WebApplication without Constructor

php,oop,yii
In bootstrap of Yii 1.1 (app/index.php, Line 13), we boot up application with Yii::createWebApplication($config)->run(); command and createWebApplication method is (framework/YiiBase.php, Line 96) public static function createWebApplication($config=null) { return self::createApplication('CWebApplication',$config); } such that createWebApplication method is (framework/YiiBase, Line 123) public static function createApplication($class,$config=null) { return new $class($config); } So createApplication('CWebApplication',$config) interpret...

how to get the current action id in Yii?

php,url,yii,action
I need a function to get the current action Id, for example if the url is /controller/view/5 I want to get the 5 which is the action Id, how I can do that in Yii?

Yii UrlManager Action OR Controller

php,regex,url,yii,yii-url-manager
Is it possible in Yii UrlManager rules to set rule OR site/? For example there's "action Contacts in SiteController" and "controller MediController". Yii must use action from SiteController if it exists or user MediaController/index if not.

Yii1 Detail View , how to add class to image

php,yii,detailview
I am using yii1 and facing problem in adding class to image shown in detail view , tell me how to add css class or static property to image to make width and height 40px; my detail view code is below <?php $this->widget('zii.widgets.CDetailView', array( 'data' => $model, 'attributes' => array(...

Yii will not move_uploaded_file - 500 internal server error

php,jquery,yii,blueimp
I'm using the blueimp File Upload Plugin with Yii to try and upload a file to my server (currently localhost). I gave the folder full read / write permissions (the location is C:\xampp\htdocs\yii), but I still get an error when I try to do the move_uploaded file command. Here is...

How to load jquery-1.11.2 with bootstrap and booster?

jquery,twitter-bootstrap,yii,yii-extensions,yii-booster
I am using yii framework with Boostrap and Booster. On my web page i need to use jQuery version 1.9.1. When i include it eg $cs->registerScriptFile($baseUrl . '/js/jquery-1.11.2.min.js') i start getting all kinds of Jquery errors eg jQuery(...).rating is not a function ect.. I need to include the jquery1.11.2 in...

translation issue in php

php,yii,internationalization,translation
I have done everything that is needed to translation. only issue is this word is not getting translated properly, L’équipe is not getting translated properly, instead of it i am getting L?équipe with a question mark which i dont understand how. This is how the code is written. $body =...

Handling Guests in Yii2 to prevent constant checks

php,yii,yii2,yii2-user
I'm wondering what is generally the recommended way to handle guests in Yii2. Like, for example when you have a logged in user you can simply get their details via a call such as: $user = Yii::$app->user->identity; Then you can do stuff like the below, depending on what details you...