473,796 Members | 2,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using a view with some parameters

Hello,

I try to develop an application with a controller (which acts as the
model also, meaning it performs calls to db and all this) and a view.

For example, there's a controller called professor which will act upon
members of the site (teachers, professors) who will login.

In my class professor I have a function:
function login() {
$loginForm=new professorLoginF orm("professors/login");
if($this->_post) {
....
} else {
$this->todisplay=$log inForm->ShowLogin();

}
}

Since I 'm not posting the form now the $loginForm->ShowLogin(); is
executed.

professorLoginF orm is an extension of LoginForm where I have a function:

function ShowLogin($logi nErrors="") {
if($this->use_cookies) {
$loginCookie=$t his->GetCookie();
$loginvars['email']=$loginCookie['email'];
$loginvars['password']=$loginCookie['password'];
}
$loginvars['use_cookies']=$this->use_cookies;
$loginvars['action']=$this->action;

if($loginErrors !="") $loginvars['errors']=$loginErrors;

$logform=get_in clude_contents( 'views/generalLoginFor m.php');

return $logform;
}

and another function

function get_include_con tents($filename ) {
if (is_file($filen ame)) {
ob_start();
include( $filename);
$contents = ob_get_contents ();
ob_end_clean();
return $contents;
}
return false;
}

The problem is in the views/generalLoginFor m.php. The beginning of it has:
<?php global $loginvars,$log inclassname;?>
<form class="<?php echo $loginclassname ; ?>" action="<?php echo
$loginvars['action']; ?>"

$loginvars and $loginclassname is always "". Why is that?

The reason for using the get_include_con tents instead of just including
it is because in my controller I have a function:

function Display() {

include('static pages/header.php');
print $this->todisplay;
include('static pages/footer.php');
}

I know this may be a wrong approach and I would like to comment on it if
so.

Thanks and sorry for the huge post.

Harris
Jun 27 '08 #1
6 1299
On Jun 12, 11:37 am, Harris Kosmidhs
<hkosm...@remov e.me.softnet.tu c.grwrote:
<snip>
function ShowLogin($logi nErrors="") {
....
$loginvars['use_cookies']=$this->use_cookies;
$loginvars['action']=$this->action;

if($loginErrors !="") $loginvars['errors']=$loginErrors;

$logform=get_in clude_contents( 'views/generalLoginFor m.php');

return $logform;
}
<snip>
The problem is in the views/generalLoginFor m.php. The beginning of it has:
<?php global $loginvars,$log inclassname;?>
<form class="<?php echo $loginclassname ; ?>" action="<?php echo
$loginvars['action']; ?>"

$loginvars and $loginclassname is always "". Why is that?
Because they are not in the global scope.

C
Jun 27 '08 #2
C. (http://symcbean.blogspot.com/) wrote:
On Jun 12, 11:37 am, Harris Kosmidhs
<hkosm...@remov e.me.softnet.tu c.grwrote:
<snip>
>function ShowLogin($logi nErrors="") {
...
> $loginvars['use_cookies']=$this->use_cookies;
$loginvars['action']=$this->action;

if($loginErrors !="") $loginvars['errors']=$loginErrors;

$logform=get_in clude_contents( 'views/generalLoginFor m.php');

return $logform;
}
<snip>
>The problem is in the views/generalLoginFor m.php. The beginning of it has:
<?php global $loginvars,$log inclassname;?>
<form class="<?php echo $loginclassname ; ?>" action="<?php echo
$loginvars['action']; ?>"

$loginvars and $loginclassname is always "". Why is that?

Because they are not in the global scope.

C
because the function get_include_con tents is in another file?

How can I overcome it?
Jun 27 '08 #3
Harris Kosmidhs escribió:
>>function ShowLogin($logi nErrors="") {
...
>> $loginvars['use_cookies']=$this->use_cookies;
$loginvars['action']=$this->action;

if($loginErrors !="") $loginvars['errors']=$loginErrors;

$logform=get_in clude_contents( 'views/generalLoginFor m.php');

return $logform;
}
[...]
>Because they are not in the global scope.
[...]
because the function get_include_con tents is in another file?
Variable scope has nothing to do with files. If you want to use global
variables inside a function you need to load it with the global keyword:

function ShowLogin($logi nErrors="") {
global $loginvars;
$loginvars['use_cookies']=$this->use_cookies;
...
}

Otherwise, whatever variables you handle are considered local to the
function. That prevents undesired side effects.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño Mar*a: http://www.demogracia.com
--
Jun 27 '08 #4
Álvaro G. Vicario wrote:
Harris Kosmidhs escribió:
>>>function ShowLogin($logi nErrors="") {
...
$loginvars['use_cookies']=$this->use_cookies;
$loginvars['action']=$this->action;

if($loginErrors !="") $loginvars['errors']=$loginErrors;

$logform=get_in clude_contents( 'views/generalLoginFor m.php');

return $logform;
}
[...]
>>Because they are not in the global scope.
[...]
>because the function get_include_con tents is in another file?

Variable scope has nothing to do with files. If you want to use global
variables inside a function you need to load it with the global keyword:

function ShowLogin($logi nErrors="") {
global $loginvars;
$loginvars['use_cookies']=$this->use_cookies;
...
}

Otherwise, whatever variables you handle are considered local to the
function. That prevents undesired side effects.

At the same time, it is not a good idea to use global variables. They
make bugs much harder to find.

Rather, return the value(s) from the function, or pass variables by
reference to the function.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Jun 27 '08 #5
Jerry Stuckle wrote:
Álvaro G. Vicario wrote:
>Harris Kosmidhs escribió:
>>>>function ShowLogin($logi nErrors="") {
...
$loginvars['use_cookies']=$this->use_cookies;
$loginvars['action']=$this->action;
>
if($loginErrors !="") $loginvars['errors']=$loginErrors;
>
$logform=get_in clude_contents( 'views/generalLoginFor m.php');
>
return $logform;
}
[...]
>>>Because they are not in the global scope.
[...]
>>because the function get_include_con tents is in another file?

Variable scope has nothing to do with files. If you want to use global
variables inside a function you need to load it with the global keyword:

function ShowLogin($logi nErrors="") {
global $loginvars;
$loginvars['use_cookies']=$this->use_cookies;
...
}

Otherwise, whatever variables you handle are considered local to the
function. That prevents undesired side effects.


At the same time, it is not a good idea to use global variables. They
make bugs much harder to find.

Rather, return the value(s) from the function, or pass variables by
reference to the function.
Can you please explain how can I do this? I understand the problem but
can't find out a solution. How do templates handle passed variables?

Thanks
Jun 27 '08 #6
Harris Kosmidhs wrote:
Jerry Stuckle wrote:
>Álvaro G. Vicario wrote:
>>Harris Kosmidhs escribió:
>function ShowLogin($logi nErrors="") {
...
> $loginvars['use_cookies']=$this->use_cookies;
> $loginvars['action']=$this->action;
>>
> if($loginErrors !="") $loginvars['errors']=$loginErrors;
>>
> $logform=get_in clude_contents( 'views/generalLoginFor m.php');
>>
> return $logform;
> }
[...]
Because they are not in the global scope.
[...]
because the function get_include_con tents is in another file?

Variable scope has nothing to do with files. If you want to use
global variables inside a function you need to load it with the
global keyword:

function ShowLogin($logi nErrors="") {
global $loginvars;
$loginvars['use_cookies']=$this->use_cookies;
...
}

Otherwise, whatever variables you handle are considered local to the
function. That prevents undesired side effects.


At the same time, it is not a good idea to use global variables. They
make bugs much harder to find.

Rather, return the value(s) from the function, or pass variables by
reference to the function.

Can you please explain how can I do this? I understand the problem but
can't find out a solution. How do templates handle passed variables?

Thanks
Just like I said - if they need to change a value, they use references
or return a value. They don't do anything any different.

The php manual has a lot of good stuff on both passing by reference and
returning values from functions.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
6706
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J# .NET version of this article, see 320627. This article refers to the following Microsoft .NET...
1
4466
by: Fran?ois Bourdages | last post by:
Hi is there a way to know if object (view, function, etc) are invalid ? let say a have a table t1 (field col1, col2) and a view v1 (field t1.col1, t1.col2) if I drop t1.col2, the view v1 is not working anymore. I want to know that information. In Oracle (8.1.7), i can query the all_objects, user_object table, where status = 'INVALID'. So i can recompile invalid objects (or
11
13514
by: Paul Reddin | last post by:
Hi, This is a real hopeful one! What we are trying to do: 1. We MUST present a mappable database object for our application objects i.e a Table or a View Some of the views are very complex, which raises another couple of
1
3568
by: Joseph Del Medico | last post by:
I'm trying to use a query whose SQL view is shown below to get a recordset of all first quarter records from a table for a year that is in the textbox of a form, so I can sum up the totals for the first quarter for every person and display them on the form. The query works fine when I preview it in the query builder, but when I try to open a recordset in vb code with the query I get "too few parameters expected one". It seems for some...
11
6603
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on where the job is running, the job runs sucessfully, PDF files got generated, everything is good. If I scheduled the job to run at the time that I am not logged into the server, Access is not able to print to the printer. The error is pretty...
0
2582
by: billmiami2 | last post by:
Perhaps many of you MS Access fanatics already know this, but it seems that stored procedures and views are possible in Jet. I thought I would leave this message just in case it would help anyone. I discovered this the other day while doing some experiments with ADO and ADO.NET. Basically, I wanted to run a stored MS Access query with parameters using the syntax Execute MyProcedure @Param1, @Param2...
13
4868
by: Filips Benoit | last post by:
Dear All, How can I show the resultrecords of a SP. I can be done by doubleclick the SPname? But how to do it by code. I want the following interface In my form the user 1 selects a SP (combobox showing a userfrinly name) 2 adds the related parameters
7
6994
by: Serge Rielau | last post by:
Hi all, Following Ian's passionate postings on problems with ALTOBJ and the alter table wizard in the control center I'll try to explain how to use ALTOBJ with this thread. I'm not going to get into the GUI because it is hard to describe in text. First of all what is the purpose of ALTOBJ()? This procedure was created mostly for ISVs who need to do produce change scripts to upgrade application from release to release, but it can also
0
7672
MMcCarthy
by: MMcCarthy | last post by:
Rather than using the Access design view change the view to SQL. I am going to attempt to outline the general syntax used for SQL queries in Access. Angle brackets <> are used in place of some syntax elements you must supply. The description of these elements will be in the contained in the angle brackets. Square brackets are used to show which parts are optional. Basic SELECT query SELECT <field list> FROM <table/query name(s)>
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9524
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10168
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.