yii,routing , simple routing in yii framework 1


simple routing in yii framework 1

Question:

Tag: 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 ; 
            }
        }

I m using this code :-

'urlManager'=>array(
            'urlFormat'=>'path',
            'showScriptName'=>false,
            'appendParams' => false,
            'caseSensitive'=>false, 
            'rules'=>array(
                array(
                    'class' => 'application.components.IndexUrlRule',
                    'connectionID' => 'db',
                ),
                array(
                        'contact_us' => 'site/page/contact_us',
                          ),
                array(
                        'class' => 'application.components.PageUrlRule',
                        'connectionID' => 'db',
                ),                      
                '<_c:index|trade|page>'=>'<_c>/index',
                'page/<page_id:\d+>' => 'page/show'
            ),
        ),

Answer:

You need to configure in your Url Manager in config file like this -

 'urlManager'=>array(
        'urlFormat'=>'path',
        'showScriptName'=>false,
        'rules'=>array(
            'contact_us'=> 'site/page/contact_us',
        )
    )

After your url -

www.example.com/contact_us


Related:


Node forward path request to another server


node.js,express,routing,routes,request
Currently have a website running a node server that handles all requests for example.com and I created a completely separate wordpress blog on a separate server (running apache) that I would like served on a path like example.com/blog at 172.23.23.23 IP address. The wordpress server doesn't share any code or...

Re-transmission concept in TCP


tcp,routing,tcp-ip,osi
Server sent data to client, but client didn't send ACK for the data . So once RTT completed , Server will resend data to client again .... like that how long it will try to send the data ? What is the maximum time server will try to send the...

I don't understand routing


php,routing,flightphp
I am trying to learn a PHP framework. But I'm having some difficulties understanding some of the concepts of routing. I've chosen to use Flight. Their homepage shows: require 'flight/Flight.php'; Flight::route('/', function(){ echo 'hello world!'; }); Flight::start(); And I don't understand what they're using Flight::route... for. What am I missing?...

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

Why does this MVC action return a 404 response in IE11


ajax,asp.net-mvc,routing
I have written an mvc action that works in Chrome and Firefox but not in IE11. Using IE11 it returns a 404 response code. Controller: [HttpDelete] public ActionResult DeleteAction(int ActionID) { return Json(_Logic.DeleteAction(ActionID), JsonRequestBehavior.DenyGet); } Calling JS: Ajax_Proxy.DeleteAction = function (_actionID, successCallback, failureCallback) { return $.ajax({ type: "DELETE", datatype: 'json',...

No action was found on the controller that matches the request


c#,asp.net,ajax,asp.net-mvc,routing
Sorry for the lame question. I've already read all similar questions and still can't resolve my issue. I'm getting 'No action was found on the controller that matches the request' error when calling from ajax: $.ajax({ url: '/api/ToyEdit/Post/', dataType: "json", type: "POST", contentType: 'application/json; charset=utf-8', data: JSON.stringify({toyId: 1, toy: 'asd'}),...

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

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; } ...

Symfony/Twig how to render a Route set by anotation?


php,symfony2,routing,twig,url-routing
Let's say I have this code in a controller: <?php namespace Foo\BarBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration as Mvc; /** * @Mvc\Route("/foo/bar") */ class TestController extends Controller /** * @Mvc\Route("/test/{id}", requirements={"id" = "[0-9]{1,6}"}) * @Mvc\Template * * @return view */ public function testAction($id) { return array('test' => $id); } } How...

How to access UrlHelper.Action or similar from within Global asax


c#,routing,asp.net-mvc-5
I am trying to prepare a 301 redirect for a typo I made 'recieved' I am struggling to find a way of getting the url from the action and controller names. I am aware of UrlHelper.Action but it does not exist within Global.asax. How do I gain access to this...

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

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

Rails routing link to specific show


ruby-on-rails-4,routing
This question seems a little basic, but considering I have 'pages#show' with a show page with url 'history'. How could I add this specific show page to a link: = link_to 'History', pages_path(@?????) PD1: I would prefer avoid using :id since I tend to seed a lot of data, and...

$StateProvider Remove Child View Nesting


angularjs,routing,angular-ui-router,angularjs-ui-router
I am new to angular ui routing . I am creating a sample application and want to display parent and child view separately . I mean when parent item gets selected child view will be displayed and parent view would be hidden . If I add ui-view to parent view...

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

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)); ?> ...

Codeigniter Select JSON, Insert JSON


json,codeigniter,select,insert,routing
I have very simple users database: user_id, user_name, user_email My model this: class Users extends CI_Model { private $table; private $table_fields; private $table_fields_join; function __construct() { parent::__construct(); $this->table = 'users'; $this->table_fields = array( $this->table.'.user_id', $this->table.'.user_name', $this->table.'.user_email' ); $this->table_fields_join = array(); } function select(){ $this->db->select(implode(', ', array_merge($this->table_fields, $this->table_fields_join)));...

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

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", "");...

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+>' =>...

Open page url in modal on a page (Facebook Photo URLs)


javascript,jquery,angularjs,routing,angularjs-routing
P.S. I am using html5Mode to remove '#' in routing in below scenario Removing the hashtag from AngularJS urls (# symbol) Consider I have two main pages.One is photos where thumbnails are provided and whose url is /someSlug/photos. Other is the url of a single photo '/someSlug/photos/somePhotoId' which shows a...

Angular $routeProvider and Controller As Syntax


angularjs,routing,angularjs-scope,angularjs-routing,ngroute
Can anyone tell me if it is valid to use $routeProvider with Controller as syntax? I am having issues accessing <h1>{{kickController.foo}}</h1> from the controller where this.foo resides. angular.module('ucp.kick', ['ngRoute']).config(function($routeProvider, APP_BASE_URL) { return $routeProvider.when(APP_BASE_URL + 'kicks', { reloadOnSearch: false, navitem: true, name: 'Kicks', templateUrl: 'kick/partials/kick.html', controller: 'kick as KickController' }); });...

WebApi Routing not working for Post


routing,asp.net-web-api2,asp.net-web-api-routing
My WebApiConfig has following routes // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { controller = "Employee", action = "Get", id = RouteParameter.Optional } ); The Post WebApi method has got following Signatures [HttpPost] public IHttpActionResult Post(Employee emp) { ..... } When i try to call...

Asp.net MVC Routelink null controller parameter


c#,asp.net,asp.net-mvc,asp.net-mvc-4,routing
I have two routes, the default one routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); I added another route, sometimes the parameter will by a string routes.MapRoute( name: "ByName", url: "{controller}/{action}/{name}", defaults: new { controller = "Home", action =...

How to deal with extra “/” in phpleague route?


php,web-services,routing
I am setting endpoints for my web application like this: $router = new League\Route\RouteCollection; function user_action (Request $request, Response $response) { // some logic . . . return $response; } $router->addRoute('GET', '/user', 'user_action'); /user endpoint works well. However when I use /user/ (extra slash in the end) I get a...

Select Mongoose Model Based on Express Route


express,routing,mongoose
I think this might be a basic question, but looking for the best approach. I'm building an express app that should route to one of four different Mongoose models depending on the route. Something like this: app.get('/:trial', function(req, res){ var trial = req.params.trial; trial.find(function(err, records) { if (err) res.send(err); res.json(records);...

Where should I put Symfony third-party bundle's routing configuration?


php,symfony2,routing,symfony-routing
I have SonataAdminBundle, SonataUserBundle and LiipImagineBundle installed in my Symfony 2 application. According to their installation instruction, I put their routing configuration in /app/config/routing.yml. _liip_imagine: resource: "@LiipImagineBundle/Resources/config/routing.xml" admin: resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml" prefix: /admin _sonata_admin: resource: . type: sonata_admin prefix: /admin sonata_user: resource: '@SonataUserBundle/Resources/config/routing/admin_security.xml' prefix: /admin...

Multiple routes with multiple domains


symfony2,routing
Let's say I've got a website with multiple (sub)domains: acme.com (USA) acme.nl (Netherlands) be.acme.eu (Belgium) de.acme.eu (Germany) fr.acme.eu (France) etc... I thought this should be very simple to configure, so I made this routing.yml: usa: host: "acme.com" resource: "@WebsiteBundle/Controller/" type: annotation defaults: country: "en" netherlands: host: "acme.nl" resource: "@WebsiteBundle/Controller/" type:...

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

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

Is it possible in laravel 5 to show a pretty url to the user, and a practical url to the app?


routing,routes,laravel-5,friendly-url,slug
I have this url: mywebsite.com/user/1/edit I want my users to see this: mywebsite.com/edit-your-profile/ Is this possible when using Route::resource('user', 'UserController');? If yes, how do I do it :) ? I still want my app to be able to see user/1/edit as I use it in my middleware to prevent unauthorized...

Route parameter with slash “/” in URL


asp.net-web-api,routing,asp.net-web-api2,asp.net-web-api-routing,attributerouting
I know you can apply a wildcard in the route attribute to allow / such as date input for example: [Route("orders/{*orderdate}")] The problem with wildcard is only applicable to the last paramter in URI. How do I solve the issue if want to have the following URI: [Route("orders/{orderdate}/customers")] ? EDIT:...

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

Ruby-on-Rails Voting Partial Routing


ruby-on-rails,routing,voting
I have a voting feature on my app but can't route back to the same page with the vote applied. I know I have to fill in the link_to methods but my understanding of routing/ruby syntax is a bit limited, so I'm not even sure [post, vote] is correct. I...

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

Restrict laravel to open url that is not in route


php,laravel,routing,laravel-5,laravel-5.1
I am Learning laravel now. Today I came across a problem that surprised me. I open this link in my browser: http://localhost/laravel/project/ch/resources/views/pages/blog.blade.php And I expect error 404. but it opens contains of this file. So, How to restrict laravel to do this. I want laravel to open only url mentioned...

SAPUI5/OPENUI5 - Routing with Dialogs


routing,dialog,sapui5,openui5
I´m currently stuck with the combination of routing and dialogs. I have a view with list elements and when I click on an element in the list I want the Detail view to be shown in a Dialog (Popup). The thing is, I also want the ID of the list...

Change resources path


ruby-on-rails,ruby,routing
I'm using Rails 4 I have a routes.rb file that looks like: resources :books However, I'd like the urls in the application to end up looking like /b/101 instead of /books/101. I realize I could go through and rename each resource path individually, but is there not a way to...

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

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

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

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

How to add menus/ subtopics for meteor site?


javascript,node.js,meteor,routing,meteor-blaze
I am new to meteor. I followed the tutorials and successfully making simple interfaces like below. I tried finding examples to add menus/ subtopics like this which does not reload the page when clicked, but I couldn't find any examples. Could you please give me an example how to do...

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

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

Routing in Sinatra


ruby,web,routing,sinatra
I have an application where the user fills out a form at /search and I want that to output to /search/results. In my app.rb, I've attempted to call post '/search' do ... erb :search/results end However that fails. My directory structure is: views -search --results But it fails. Where am...

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

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 { //...