tesla Posted June 6, 2011 Report Share Posted June 6, 2011 Hello I'm a PHP-beginner and new member of this community and the university, great videos! I learned a lot in the last month. Now I've a problem with my small application, I changed a lot and can't find a good solution. (i went through many tutorials, google, killerphp-videos) My Application has a searchForm, which works fine, but I'd like to switch to the admin section where I can use the same form and other functions. My FirstVersion (after x-versions that didn't work) looks like that: <?php /* Controller class */ error_reporting(E_ALL); class Controller { public $model; public function __construct($server, $user, $pass, $database) { $db = new mysqli($server, $user, $pass, $database); include (APP_PATH . "model/model.php"); $this->model = new Model($db); } public function loginLink() { if(isset($_GET['login'])) { echo "<a href='?'>Admin Logout</a>"; $_SESSION['loggedin'] = TRUE; $this->content(); } else { echo "<a href='?login'>Admin Login</a>"; $_SESSION['loggedin'] = FALSE; } } public function content() { if ($this->model->checkLoginStatus()) { include('views/searchAdmin.php'); } else { include('views/search.php'); } } public function search($var1, $var2) { if($this->model->checkLoginStatus() == FALSE) { include('views/search.php'); return FALSE; } } if ($rates = $this->model->getData($var1, $var2)) { if($this->model->checkLoginStatus() == FALSE) { include('views/search.php'); include('views/result.php'); } } else { if($this->model->checkLoginStatus() == FALSE) { include('views/search.php'); } } } } ?> I learned a lot from the your tutorial-videos, but it began to be complicated and not clean. the new version looks like this: <?php /* Controller class */ error_reporting(E_ALL); class Controller { public $Model, $Auth, $rates; public $request = null; public $template = ''; public $view = null; public function __construct($request, $server, $user, $pass, $database) { $db = new mysqli($server, $user, $pass, $database); $this->Model = new Model($db); $this->Auth = new Auth(); $this->View = new View(); $this->request = $request; if(!empty($request['view'])) { $this->template = $request['view']; } else { $this->template = 'default'; } } public function display() { $innerView = new View(); if ($this->template == 'userSearch') { $rates = $this->search($this->request['var1'], $this->request['var2']); $innerView->setTemplate('userSearch'); $innerView->assign('rates', $this->rates); } if ($this->template == 'adminSearch') { $innerView->setTemplate('adminSearch'); } if ($this->template == 'login') { $innerView->setTemplate('login'); } if ($this->template == 'default') { $innerView->setTemplate('userSearch'); } $this->View->setTemplate('content'); $this->View->assign('content_title', 'Der Titel'); $this->View->assign('content_body', $innerView->loadTemplate()); $this->View->assign('content_footer', '© 2011 | ' . $this->loginLink()); return $this->View->loadTemplate(); } public function search($var, $var) { if(strlen($destination) == 2) { $dest_var = "dest_country"; } elseif(strlen($destination) == 3) { $dest_var = "dest_code"; } elseif(strlen($destination) > 3) { $dest_var = "dest_city"; } else { $this->template = 'default'; return FALSE; } if ($this->rates = $this->Model->getRate($var1, $var2)) { $this->template = 'userResult'; } else { $this->template = 'default'; } } public function loginLink() { return "<a href='?view=login'</a>Login"; } } ?> <?php /* View class */ class View { private $path = 'views'; //private $template = 'default'; private $template = array(); private $_ = array(); public function assign ($key, $value) { $this->_[$key] = $value; } public function setTemplate($template) { $this->template = $template; } public function loadTemplate() { $tpl = $this->template; $file = $this->path . DIRECTORY_SEPARATOR . $tpl . '.php'; ob_start(); include $file; $output = ob_get_contents(); ob_end_clean(); return $output; } } ?> this display function its not good, because when the app grows, it starts to be complicated. I watched lot of the PHP-Videos and I'd like to find a simple solution something like the CMS tutorial. I tried, but I can't apply it to my app. An PHP OOP dynamic site solution :-) (you can also refer to killerphp-videos I'll go through!) thanks for every help & best regards P.S. sorry for my bad english :-) Quote Link to comment Share on other sites More sharing options...
jbwebdesign Posted June 6, 2011 Report Share Posted June 6, 2011 what exactly are you trying to accomplish? What kind of web app are you making? Quote Link to comment Share on other sites More sharing options...
jbwebdesign Posted June 6, 2011 Report Share Posted June 6, 2011 look at the controller class public function loginLink() { return "<a href='?view=login'</a>Login"; } } this should be: public function loginLink() { return "<a href='?view=login'>Login</a>"; } } Quote Link to comment Share on other sites More sharing options...
tesla Posted June 6, 2011 Author Report Share Posted June 6, 2011 Hello & thanks for the reply I'm searching airline rates, it works. as default it shows the searchform for all users, then i'd like to change to the admin-area. there I have the same or another searchform with another functions. I like very much the Killerphp-CMS-solution, but i can't apply to my app. so I'm searching for a simple OOP PHP dynamic site solution. if you're familiar with the cms-tutorial, how would it look like when the links in the menu would work? as a exemple, the TestLink, how would the code look like only for this link in the hole application? I think that would help me a lot, because the tutorial is really great. thanks in advance P.S. sorry for my english Quote Link to comment Share on other sites More sharing options...
jbwebdesign Posted June 6, 2011 Report Share Posted June 6, 2011 I'm not sure i understand what you mean, please explain it better. do you have a link to see the website live? Quote Link to comment Share on other sites More sharing options...
tesla Posted June 7, 2011 Author Report Share Posted June 7, 2011 Good morning sorry for my explination, i try it better. it's a intranet-application, there is no access from the outside. but i think we forget about my app, I think the KillerPHP CMS-Tutorial would be a greater help if you can explain it to me, how would the code look like, when the TestLink would have a function. What I mean, there are 4 links in the menu, but they don't work, what should I update in the controllers, views to have a link to work? (you will understand if you're familiar with the KillerPHP PHP CMS Tutorial) thanks & best regards Quote Link to comment Share on other sites More sharing options...
falkencreative Posted June 8, 2011 Report Share Posted June 8, 2011 I'll take a look at this later today. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted June 8, 2011 Report Share Posted June 8, 2011 The links in the menu are created by this code (within "index.php" in the root folder): <ul id="nav"> <li><a href="#">Home</a></li> <li><a href="#">Test Link</a></li> <li><a href="#">Longer Text Link</a></li> <li><a href="#">Contact us</a></li> </ul> You would simply need to create additional .php files and update the hrefs to point to the correct files. This is exactly the same as creating links between .html files using regular HTML and CSS. No PHP is required, and you don't need to make any changes to your models, controllers or views. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.