send parameter url - cakephp

I am sending the values to a controller doing this
echo $html->link('Do this? ',"/item/view/{$form->value('table.id')}");
on the controller end cake just pickups the id like this
function view($id = null){
....
}
Now in addition to table.id, I want to send another value called table2.source ...how would I do that so the controller also gets it
function view($id = null, $source=null) ...something along those lines but not sure how will they get to the controller in first place

Can you not just change the link url to something like this:
echo $html->link('Do this? ',
"/item/view/{$form->value('table.id')}/{$form->value('table2.source')}");
(After changing the view function to accept the second parameter...)

Related

How to pass array value from view to another view Laravel 5.7

I want to get the value from the array I've passed from the first view to another view.
I found this works by using route (not url), but I don't know how to get it without parameter in the controller.
Please help me within the right syntax.
This is the latest code I've tried
$id = $request->id;
if($request->has('download', 'id')){
$pdf = PDF::loadView('pdfview');
return $pdf->download('pdfview.pdf',['id'=>$id])->with('id',$id);}
This is my code *used to download pdf file from a view
Controller
public function pdfview(Request $request)
{
$items = DB::table("items")->get();
view()->share('items',$items);
$id = $request->only(['id']);
if($request->has('download', 'id')){
$pdf = PDF::loadView('pdfview');
return $pdf->download('pdfview.pdf', ['id'=>$id])->with('id', $id);
}
return view('pdfview', ['id'=>$id])->with('id', $id);
}
Route
Route::get('pdfview',array('as'=>'pdfview','uses'=>'MaatwebsiteDemoController#pdfview'));
View
Download PDF
I want to get the $employee->nip value
But it is still Undefined variable: id
Don't really have time to test it. But this thread looks promising.
https://laravel.io/forum/03-14-2016-basics-passing-info-from-one-view-to-another

CakePHP passing values between controllers

I want to pass values from one controller to another.
For example I have a Conference controller and I want to create a new Event.
I want to pass the Conference id to the event to make sure those two objects are associated.
I would like to store in the ivar $conference using beforeFilter method.
Here is my beforeFilter function in the Events controller
public function beforeFilter() {
parent::beforeFilter();
echo '1 ' + $this->request->id;
echo '2 ' + $this->request['id'];
echo $this->request->params['id'];
if(isset( $this->request->params['id'])){
$conference_id = $this->request->params['id'];
}
else{
echo "Id Doesn't Exist";
}
}
Whenever I change url to something like:
http://localhost:8888/cake/events/id/3
or
http://localhost:8888/cake/events/id:3
I am getting an error saying that id is not defined.
How should I proceed?
when you're passing data via url you can access it via
$this->passedArgs['variable_name'];
For example if your URL is:
http://localhost/events/id:7
Then you access that id with this line
$id = $this->passedArgs['id'];
When you access a controller function that accepts parameters through url, you can use those parameters just as any other variable, like for example say your url looks like this
http://localhost/events/getid/7
Then your controller function should look like:
public function getid($id = null){
// $id would take the value of 7
// then you can use the $id as you please just like any other variable
}
In the Conferences Controller
$this->Session->write('conference_id', $this->request->id); // or the variable that stores the conference ID
In the Events controller
$conferenceId = $this->Session->read('conference_id');
Of course, on top you need
public $components = array('Session');

How to pass simple data from controller to view in cakePHP

I get an int value to the controller and I would like to send it to the according view, but i am either passing or accesing it wrong. Here is what I am trying to do:
Controller:
function send($int = NULL) {
$this->set('integer', $int);
}
View:
echo $integer['int']
Your help is much appreciated!
Change
echo $integer['int']
To:
echo $integer;
The first parameter in $this->set is used as the variable name in your view, the second parameter is the value assigned to that variable.

call action from action in one controller cakephp like controller/action/action

i have a controller called "Movies" so the link is "localhost/Movies" and have some actions in this controller like "localhost/Movies/view/[id]" , "localhost/Movies/view/category/[id]" if i want to make a path by the category name and sub category name like "localhost/Movies/English/new" .
how can i do something like this in cakephp 2. my project now like "localhost/English/new" but i want to put Movies in this path, to make it more fixable, if i want to make a new category just add a column in my database .
thanks
If i understand, maybe by creating a custom route for your action:
In app/config/routes.php:
Router::connect('/movies/:category/:subcategory', array('controller'=>'movies','action' => 'index'));
And you can retrieve the value in your controller with:
echo $this->params['category'];
echo $this->params['subcategory'];
You can also read about it in the cookbook http://book.cakephp.org/1.3/view/945/Routes-Configuration
The default routing in CakePHP is as follows:
mydomain/controller/action/param1/param2/param3/param4/...
If you want to add filter options to an action, just add optional parameters to the action.
function index($category = null, $subcategory = null) {
if(isset($subcategory)){
//will execute if you pass both arguments
}else if(isset($category)){
//will execute if you pass one argument
}else{
//will execute if you pass no arguments
}
}
EDIT
In this case, $category is param1, and $subcategory is param2. The overloaded function can receive either 1, 2, or no arguments. If this is in, for example, the ObjectsController, all these are valid URLs:
localhost/objects/index/ //$category==null, $subcategory==null
localhost/objects/index/foods/ //$category=='foods', $subcategory==null
localhost/objects/index/foods/green/ //$category=='foods', $subcategory=='green'
This allows you to control many options in the same action.

App::import not working for controller

I need to load controller class and I try:
App::import('Controller','AppController');
or
App::import('Controller','PagesController');
But this every time returns false. When I try this:
App::import('Model','AppModel');
it returns true, so it seems it's not working for controllers - why?
When using App::import(type, name) for a controller, you don't need to include "Controller" in the name you import, just when creating the instance variable.
App::import('Controller', 'Pages');
$Pages = new PagesController;

Resources