2

I want to know that is there any way to get uri segment like codeigniter provide.. In codeigniter we can do ;

$this->uri->segment(3);

to get 3rd segment of url.. Let say i have an url like;

www.example.com/param1/param2/param3/param4

How can i get parameters?

0

3 Answers 3

1

Well in the default route setup in a zend framework app you would have: modulee:/controller:/action/param:/value:/param2:/param2

So for:

/admin/news/edit/id/12/name/newstest


echo $this->getParam('id'); // prints 12
echo $this->getParam('name'); // prints newstest

Pretty sure:

echo $_GET['id'];

Should work too.

Hope this helps!

Sign up to request clarification or add additional context in comments.

2 Comments

but what if i dont have a key like id, it's just a value of params?
@tylerdurden I'd have to check tocumentation but if you set a route so that the first param is id then you should be able to get to it thru $_GET['id'] regardless of if you see the word ID in the parameter. You could also, i guess, explode the url to get to the params.
0

I came up a solution like zend router regex setting ;

    $route = new Zend_Controller_Router_Route_Regex(
                'module/(.*)',
                 array(
                        'module' => 'module',
                        'controller' => 'index',
                        'action'     => 'index'));

    $router->addRoute('module', $route);

in module index controller's index action ;

    $paramArr = explode("/",$this->_request->getParam(1));

1 Comment

Seems along way to go for simple an operation. Urls in ZF are always (unless you change it) Key value pairs. So if you know the url you know the parameters. www.example.com/key/value/key/value
0
$this->getRequest()->getParams(); //Retrieves all parameters sent
$this->getRequest()->getPost(); //Retrieves the post array
$form->getValues(); //retrieves form values

These are common ways to work with the request object, they are not

this is what to expect from $this->getRequest()->getParams();
Notice that the url parameters are module, controller, action, station = 1, submit = Submit

Params array(5) {
  ["module"] => string(5) "admin"
  ["controller"] => string(5) "index"
  ["action"] => string(5) "index"
  ["station"] => string(1) "1"
  ["submit"] => string(6) "Submit"
}

This is the same request using $this->getRequest()->getPost();

Post array(2) {
  ["station"] => string(1) "1"
  ["submit"] => string(6) "Submit"
}

to get these values on your own use Zend_Debug::dump($var, 'label'); Created with Zend Framework.

This echo $_GET['id']; is considered very bad practice in ZF.

1 Comment

it's not working because after the controller first param was expected to be a action with a view.. But currently it was a just dynamic value without view and absoulutely it's not action so I get a "page not found" error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.