I'm beginer in smarty My php function is:
public function list_special() {
Session::set('was_in_special', 'true');
if (isset($_GET['showall']) && $_GET['showall'] == 'yes') {
TPL::$s->assign('products', $this->proc->getSpecialProducts('true'));
} else {
TPL::$s->assign('products', $this->proc->getSpecialProducts());
}
TPL::$s->assign('title', 'Specialus katalogas - norėdami papildyti specialiųjų kainų sąraša, susisiekite su savo vadybininku.');
//TPL::$s->assign('products', $this->proc->getSpecialProducts());
TPL::$s->assign("pages_num", $this->proc->get_special_products_pages());
TPL::$s->assign("parameters", Request::$params[1] . "/" . Request::$params[2] . "/");
echo TPL::$s->fetch('catalog.products.html');
}
I want call this function in one page , I try use {products} but this nothing display for me
Maybe you should register the object in before display, then call method in template like this:
{object->method p1='xx' p2='xx'}
look here.
http://www.smarty.net/docsv2/en/advanced.features.tpl
Related
Sorry for my English, but what I'm trying to say is explained below.
I have a controller say ControllerCard which has an action like this.
function actionScanCard()
{
...
$this->redirect('/transaction/redeem');
...
}
In other controllers, ControllerTransaction, I am trying to get that it comes/redirected from /card/scan-card
function actionRedeem()
{
$redirectFrom = ????;
if ($redirectFrom === '/card/scan-card')
{
// some actions
}
else
throw new ForbiddenHttpException('Must scan card!');
}
How do I get this $redirectFrom value with Yii2?
You could use the remember() & previous() methods in yii\helpers\BaseUrl.
function actionScanCard()
{
...
\yii\helpers\Url::remember();
$this->redirect('/transaction/redeem');
...
}
in TransactionController (or other)
function actionRedeem()
{
$url = \yii\helpers\Url::previous();
if($url === Url::to('card/scan-card')) {
// some actions
} else{}
}
I would like to ask a question about php . That's related php function , there are two different function but whenever call this function , doesnt work below highlight(Doesnt Work Area) place .By the way , I tried call content variable from out of function and also I wrote global variable but I couldnt.
Do you know , why ?
Java () {
$res=mysql_query("SELECT * FROM candidate WHERE candidate_id=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
if(isset ($_POST['language'])) {
$deneme=$_POST['language'];
}
$file= $userRow['candidate_name'];
touch($file.'.java');
if ( isset ($_POST ['content']) )
{
file_put_contents ($file.'.java',$_POST ['content']); **Doesnt Work HERE!**
}
exec("C:\Java\java\bin\javac -verbose $file.java 2>&1" , $output, $resultCode);
.
.
.
.
.
.
}
Is there any advice about it ?
Thank you in advance
Do you sure that if ( isset ($_POST ['content']) ) is true?
Check write permissions
Execute after writing.
Instead of
Java () {
You should use:
function Java() {
// Function contents...
}
I have created my own little PHP framework for fun, however, I am having trouble passing variables from bootstrap to the views....
if I put an echo,print_r,var_dump my target variable in the bootstrap, the output is displayed in the browser before the tag... yet the target var in bootstrap.php is not available in the view, it is coming up as "" even though at the top of the page it is being output correctly....
Somethings I noticed from similar questions:
- The target variable is not being over written
- The include target path is correct and the file exists
- The file is only being included one time (include_once is only fired once)
Any ideas are greatly appreciated, I am pulling my hair out over here lol...
Source Code
https://gist.github.com/jeffreyroberts/f330ad4a164adda221aa
If you just want to display your site name, I think you can use a constant like that :
define('SITE_NAME', "Jeff's Site");
And then display it in your index.tpl :
<?php echo SITE_NAME; ?>
Or, you can send your variables to the view by extending a little bit your JLR_Core_Views :
class JLR_Core_Views
{
private $data;
public function loadView($templatePath, $data = array())
{
$this->data = $data;
$templatePath = JLR_ROOT . '/webroot/' . $templateName . '.tpl';
if(file_exists($templatePath)) {
// Yes, I know about the vuln here, this is just an example;
ob_start();
include_once $templatePath;
return ob_get_clean();
}
}
function __get($name)
{
return (isset($this->data[$name]))
? $this->data[$name]
: null;
}
}
Then, you can call your template like that :
$view = new JLR_Core_Views();
$view->loadView("index", array("sitename" => "Jeff's Site"));
And here is your index.tpl :
<?php echo $this->siteName; ?>
Below is another example of what you can do.
First, you create this class in order to store all the variables you want :
<?php
class JLR_Repository {
private static $data = array();
public function set($name, $value) {
self::$data[$name] = $value;
}
public function get($name) {
return (isset(self::$data[$name]))
? self::$data[$name]
: null;
}
}
?>
Then, when you want to store something in it :
JLR_Repository::set("sitename", "Jeff's Site");
And in your index.tpl :
<?php echo JLR_Repository::get("sitename"); ?>
try using the 'global' keyword - http://php.net/manual/en/language.variables.scope.php
Im using CodeIgniter to write a site ... I understand $_GET requests are now used like so www.website.com/function/value .. and in the controller getting a url segment is written like so:
$userId = $this->uri->segment(3, 0);
Im just wondering, when a controller loads, i want to check if there is any uri segments, if there is then push to one view, else if there isnt a uri segment push to another.
Is that possible?
cheers.
You can use your controller arguments for that too.
When accessing /user/profile/1 your controller named User will call the method profile() and pass the number 1 as the first argument to your method. Like so:
class User extends CI_Controller {
{
public function index()
{
$this->load->view("user_index");
}
public function profile ( $userId = null )
{
if( (int)$userId > 0 )
$this->load->view("user_profile");
else
$this->load->view("another_view");
}
}
This is a very basic sample and I'm just trying to show the idea.
Seems like your asking two questions...
First, to check if the request is get
public function get_test()
{
if($_SERVER['REQUEST_METHOD'] == "GET")
{
//do something from get
echo "GET";
}
else
{
//do something not get
echo "NOT GET";
}
}
The next question seemed to be checking uri segments
public function get_test()
{
if($_SERVER['REQUEST_METHOD'] == "GET")
{
//do something from get
//echo "GET";
if($this->uri->segment(3)) //is true as is not empty
{
echo $this->uri->segment(3);
}
else
{
echo "I am nothing without my URI Segment";
}
}
else
{
//do something not get
echo "NOT GET";
}
}
As I understand you can use PHP default value.
function myFunction($var1 = NULL) {... if($var1 === NULL) ...}
Now if you do not pass the param you will get the NULL value.
I am still not using version 2 of codeigniter but this framework do not accept get requests; unless you mess with the configuration. Theres a function $this->input->get('myGet') you should look around at de the codeigniter.com/user_guide
I have a very simple class
if(!isset($_GET['page'])) {
$_GET['page'] = "home";
}
class be_site {
var $thelink;
public function get_static_content($page) {
$this->check_path($page);
} // end function
private function check_path($pathfile) {
if(file_exists($pathfile)) {
$b = 1;
include_once($pathfile);
} else {
$b = 2;
include_once('error_page.php');
}
}// End Function
public function selectedurl($subpage, $linkname){
if($subpage == $this->thelink) {
echo "<strong>" . $linkname . "</strong>";
} else {
echo $linkname;
}// End if
} // End function
} /// End site class
Now I create a new object in the index.php
include('connections/functions.php'); $site_object = new be_site;
In the content are I have
//get file
if(isset($_GET['subpage'])){
$site_object->get_static_content('content/' . $_GET['subpage'] . '.php');
}else {
$berkeley_object->get_static_content('content/' . $_GET['page'] . '.php');
}
Ok so all working fine. But if an included page is called I use try to use my other method to wrap a link and make it bold if it is selected depending on the $_GET['page'] value.
for instance
<ul>
<li><a href="index.php?page=team&subpage=about" target="_self" title="opens in same window" >
<?php $site_object->thelink = "about_us";
$site_object->selectedurl($_GET['subpage'],'about Our Website'); ?>
</a>
</li>...
And so on for each link.
Now can set the variable in the object but not call the method. I get the error
Fatal error: Call to undefined method stdClass::selectedurl()
Just wondered why I am able to set the $thelink variable in the class from an included file but not call a public function?
Thanks
Change this code:
<?php $site_object->thelink = "about_us";
$site_object->selectedurl($_GET['subpage'],'about Our Website'); ?>
To this:
<?php
global $site_object;
$site_object->thelink = "about_us";
$site_object->selectedurl($_GET['subpage'],'about Our Website'); ?>
The reason this isn't working is due to the nature of using include within a function. If you use include inside a function (be_site::check_path), the variable scope is specific to that function. See http://php.net/manual/en/function.include.php example #2.