I already try this, but not success.
URL IS: domain.com/grand/parent/child
In routes
$route['grand/(:any)'] = "smm/index/$1";
In Controller
public function index($parent = NULL){
// This is parent option//
Echo '$parent';
// This is child Section
Echo '$child';
}
My Question is: How can i echo $child ?
Thanks in advance
$route['grand/(:any)/(:any)'] = 'grand/index/$1/$2';
and
public function index($parent,$child){
echo $child;
}
should work.
Related
I have this route:
Route::get('/test',['as'=>'test','custom_key'=>'custom_value','uses'=>'TestController#index'])
I've been tried to use $routeProfile=route('test');
But the result is returned url string http://domain.app/test
I need ['as'=>'test','custom_key'=>'custom_value'] so that I can get the $routeProfile['custom_key']
How can I get 'custom_value' based on route name ?
For fastest way, now I use this for my question:
function routeProfile($routeName)
{
$routes = Route::getRoutes();
foreach ($routes as $route) {
$action = $route->getAction();
if (!empty($action['as']) && $routeName == $action['as']) {
$action['methods'] = $route->methods();
$action['parameters'] = $route->parameters();
$action['parametersNames'] = $route->parametersNames();
return $action;
}
}
}
If there's any better answer, I will be appreciate it.
Thanks...
Try this:
use Illuminate\Support\Facades\Route;
$customKey = Route::current()->getAction()['custom_key'];
I believe you are looking for a way to pass variable to your route
Route::get('/test/{custom_key}',[
'uses'=>'TestController#index',
'as'=>'test'
]);
You could generate a valid URL like so using
route('test',['custom_key'=>'custom_key_vale'])
In your view:
<a href="{route('test',['custom_key'=>'custom_key_vale'])}"
In your controller method:
....
public function test(Request $request)
{
$custom_key = $request->custom_key;
}
....
You can try one of the below code:
1. Add use Illuminate\Http\Request; after namespace line code
public function welcome(Request $request)
{
$request->route()->getAction()['custom_key'];
}
2. OR with a facade
Add use Route; after namespace line code
and use below into your method
public function welcome()
{
Route::getCurrentRoute()->getAction()['custom_key'];
}
Both are tested and working fine!
I read a lot about the Blank Page after Redirect::to() in Laravel 4.2. Here is my controller function:
public function profile($salon_id){
$salon_profile = $this->mSalon->getSalon($salon_id);
if(Session::get("user_type.dist_content_filter") && Session::get("user.distributor_id")!=$salon_profile["distributor_id"]){
return Redirect::to('error/401');
}
$lstDistributors = $this->mDistributor->getDistributors(array());
$lstCountries = (new Countries)->getCountries();
View::share('lstCountries', $lstCountries);
View::share('lstDistributors', $lstDistributors);
View::share('salon_profile', $salon_profile);
if(Session::get('success')){
View::share('box_message', array("type"=>"Success","message"=>"Distributor saved successfully"));
}
self::setCSS("header",Config::get('cdn.css_path') . "datepicker.css");
self::setJS("footer",Config::get('cdn.js_path') . "jquery.validate.min.js");
self::setJS("footer",Config::get('cdn.js_path') . "date-time/bootstrap-datepicker.min.js");
self::setJS("footer",Config::get('cdn.js_path') . "jquery.maskedinput.min.js");
echo View::make('common/header');
echo View::make('salon/profile');
echo View::make('common/footer');
}
My route:
Route::group(array('prefix' => 'error'), function(){
Route::get('/{error_number}', 'ErrorController#showError');
});
Can someone help me why I getting the Blank Page?
Thanks,
Gustavo
I found the problem, it was my mistake. The routs for this profile don't call direct the profile method:
Route::get('/{action}/{object_id}', 'SalonController#action');
So, in my Controller I have (the wrong solution):
public function action($action, $object_id = null){
if(method_exists($this,$action)){
$this->$action($object_id);
}else{
return App::missing();
}}
Correct solution:
public function action($action, $object_id = null){
if(method_exists($this,$action)){
return $this->$action($object_id);
}else{
return App::missing();
}}
I needed to include the return in the line: $this->$action.....
Thanks
Here is my controller code
function index() {
echo $this->session->flashdata('message');
$this->load->view('categoryView');
}
function delete() {
$products = $this->item_model->get_category_id($category_id);
if (count($products)) {
$message = 'Category Name is used by the product. Please change them to another category!';
}
else {
$category_id = $this->product_category_model->delete($category_id);
$message = ($category_id) ? 'Category Deleted Successfully' : 'Failed to Delete Category';
}
$this->session->set_flashdata('message', $message);
redirect('category', 'refresh');
}
After calling the delete function the flashdata has to be set and retrieve that value in index() function of the same controller but I can't.
Am also tried the $this->session->keep_flashdata('message'); before redirect to index function. But still am not get any value in index function.
Also changed $config['sess_expire_on_close'] = FALSE; to $config['sess_expire_on_close'] = TRUE; Still am not get the result.
I am wasted more time(nearly half day). Please anybody help to retrieve the flas data in codeigniter.
There are several probabilities:
1- Check your browser cookie. See if it allows cookies or if any other extension is intervening.
2- Refresh might not send the browser a new request (which thus mean a new URL). Try it for another controller see if it make any change
3- hard code the set_flashdata() with hard-coded value than a variable. set_flashdata("message", "Thank you");
In codeingitor you cannot echo anything in controller.
You have to set in $this->session->flashdata('message'); in view file not in index() function of controller
Try again by putting $this->session->flashdata('message'); in "categoryView" file where you want to display flash message.
You could try:
function set_flashdata_notification($notify_type, $msg, $error_code = null)
{
$ci =& get_instance();
$flashdata_data = set_notification_array($notify_type, $msg, $error_code);
$ci->session->set_flashdata($flashdata_data);
}
function delete() {
$products = $this->item_model->get_category_id($category_id);
if (count($products)) {
set_flashdata_notification('Category Name is used by the product.','Please change them to another category!');
redirect('path_to_view/view','refresh');
}
I am trying to validate a form submission in Kohana 3. I have the form::open point to my action_create in my controller which successfully validates the data posted to it from the form in my view. If the data passes validation, a new item is created as intended, and the user is redirected to the item that was just created. This works correctly. If the data fails validation, however, I would like the user to be directed back to the originating view/page while retaining a variable containing the data that was posted so that I can repopulate the form and display errors.
In short, how can I pass data from a view -> controller -> original view?
Thank you, everyone!
The user also posed this question on the Kohana forums.
Those seeking an answer to this should have look over there.
I assume you're using Controller_Template.
File views/form.php:
// Set default variables if variables not passed to this view
$username = isset($username) ? $username : '';
echo Form::open('login');
// Input: username
echo Form::label('username', 'Username');
echo Form::input('username', $username);
echo isset($errors['username']) ? $errors['username'] : '';
// Input: username
echo Form::label('password', 'Password');
echo Form::input('password', $password);
echo isset($errors['password']) ? $errors['password'] : '';
echo Form::close();
File views/template.php
<html>
<head><title>My Website</title></head>
<body>
<?php echo isset($content) ? $content : ''; ?>
</body>
</html>
File classes/controller/user.php
Class Controller_User extends Controller_Template {
public $template = 'template';
public function index()
{
$this->template->content = $this->display_form('form');
}
public function login()
{
// Setup validation & rules here
// Check validation, assume $validation is Validation object
if ($validation->check()
{
// Validation succeeded. Do anything you want here
}
else
{
// Validation failed. Display form with entered values
$form_vars = $_POST;
$form_vars['errors'] = $validation->errors();
// Display form
$this->template->content = $this->display_form('form', $form_vars);
}
}
// Displaying form
private function display_form($form_file, $form_vars=NULL)
{
$form = View::factory($form_file);
if ($form_vars != NULL)
{
foreach($form_vars as $key => $value)
{
$form->$key = $value;
}
}
return $form;
}
}
Hope that helps!
I new in Zend.
Main Question:
Is this code good for user login (Its beginning- because that I want to know if its can be improve)?
Thanks
view index.phtml
<? echo $this->form
controller IndexAction.php
public function indexAction() {
$form=new Application_Form_Login();
$this->view->form = $form;
if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
if ($form->isValid($formData)) {
echo " test value username: ".$form->getValue('username');
}
}
}
form Login.php
public function init() {
$this->setMethod('post');
$this->setName('user login');
$username = new Zend_Form_Element_Text('username');
$username->setLabel("username")
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty');
$password = new Zend_Form_Element_Password('password');
$password->setLabel('password')
->setRequired(true)
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('NotEmpty');
$submit = new Zend_Form_Element_Submit('submit');
$this->addElements(array($username, $password, $submit));
}
So far, so good. IMO there's nothing to improve on this further. It renders the form and if the request is POST it validates the form against the data in the POST array.
what is really special in your code? standart pattern.