PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 9, 2022

[FIXED] How to pass value to controller through URL in YII framework of php?

 January 09, 2022     php, url, yii     No comments   

Issue

This is the code

 <a type="button" class="btn btn-info" href="<?php echo CHtml::normalizeUrl(array(Yii::app()->controller->getId() . '/createStudent')); ?>">Add Student</a>

I want to pass class ID to the controller create student along with the url. The class id is in the variable

<?php $classId = $selectedSchoolClass->getId();?>

Solution

If I understand you, you have almost did it, you should only concatenate it with the & caracter and send the new param/data with the URL:

Yii::app()->controller->getId() . '/createStudent&classId='.$classId;

From the controller you can receive the data with:

$request = Yii::$app->request;
$classId = $request->get('classId');
// equivalent to: $classId = isset($_GET['classId']) ? $_GET['classId'] : null;

Hope it helps!



Answered By - JP. Aulet
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing