Lifelogger
(Peter Verbrugge)
April 19, 2015, 2:53pm
1
Hi,
I have question. I suddenly have an issue that I can not explain.
I have a controller with a bunch of actions. I want to create a new record and I use the create function that was generated by Gii. I want to add a variable to the function. So I do this:
public function actionCreate($category_id)
{
//function is stripped.
}
I open the url using /category/create/4. 4 is the category id. This doesn’t seem to work. I get an 400 error and it says it’s missing the category_id is missing. If I change $category_id to $id it works. However, the update function, etc. also have a $category_id variable and that does work too.
So, who can explain to me why the $category_id does not work in the create function, but does in the update function?
Best regards.
P.s. i have seo friendly url’s set.
Bizley
(Bizley)
April 20, 2015, 7:33am
2
I guess your url rule for this is:
'category/create/<id:\d+>' => 'category/create',
instead of
'category/create/<category_id:\d+>' => 'category/create',
rupsk1607
(Webin2015)
April 20, 2015, 8:32am
3
Lifelogger:
Hi,
I have question. I suddenly have an issue that I can not explain.
I have a controller with a bunch of actions. I want to create a new record and I use the create function that was generated by Gii. I want to add a variable to the function. So I do this:
public function actionCreate($category_id)
{
//function is stripped.
}
I open the url using /category/create/4. 4 is the category id. This doesn’t seem to work. I get an 400 error and it says it’s missing the category_id is missing. If I change $category_id to $id it works. However, the update function, etc. also have a $category_id variable and that does work too.
So, who can explain to me why the $category_id does not work in the create function, but does in the update function?
Best regards.
P.s. i have seo friendly url’s set.
Have u used urlrules in ur config file
if yes then checked that and also refer this
Routing and URL Creation
========================
When a Yii application starts processing a requested URL, the first step it takes is to parse the URL
into a [route](structure-controllers.md#routes). The route is then used to instantiate the corresponding
[controller action](structure-controllers.md) to handle the request. This whole process is called *routing*.
The reverse process of routing is called *URL creation*, which creates a URL from a given route
and the associated query parameters. When the created URL is later requested, the routing process can resolve it
back into the original route and query parameters.
The central piece responsible for routing and URL creation is the [[yii\web\UrlManager|URL manager]],
which is registered as the `urlManager` [application component](structure-application-components.md). The [[yii\web\UrlManager|URL manager]]
provides the [[yii\web\UrlManager::parseRequest()|parseRequest()]] method to parse an incoming request into
a route and the associated query parameters and the [[yii\web\UrlManager::createUrl()|createUrl()]] method to
create a URL from a given route and its associated query parameters.
By configuring the `urlManager` component in the application configuration, you can let your application
recognize arbitrary URL formats without modifying your existing application code. For example, you can
use the following code to create a URL for the `post/view` action:
This file has been truncated. show original
copy paste ur updateaction code.
Lifelogger
(Peter Verbrugge)
April 23, 2015, 9:46am
4
Thanks guys. It was in deed the routing that was not good. It’s solved now.