Jump to content
Killersites Forums


  • Posts

  • Joined

  • Last visited

About jp612

  • Birthday 12/06/1992

Profile Information

  • Gender

jp612's Achievements


Newbie (1/14)



  1. Oops, I didn't turn on the rewrite module in WAMP. My problem is fixed now.
  2. Hi, Just started trying some MVC organisation with PHP but I think theres something wrong with my .htaccess since i get this error: "The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log." My htaccess looks like this: RewriteEngine On RewriteBase /test_mvc/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [QSA.L] I also have these files and classes: index.php <?php // define site url define("BASE_PATH", "http://localhost"); // define our base path $path = "/my_mvc"; // Take the initial PATH. $url = $_SERVER['REQUEST_URI']; $url = str_replace($path,"",$url); //make array from rest or url $array_tmp_uri = preg_split('[\\/]',$url -1, PREG_SPLIT_NO_EMPTY); //Here, we will define what is what in the URL $array_uri['controller'] = $array_tmp_uri[0]; //a class $array_uri['method'] = $array_tmp_uri[1]; //a função $array_uri['var'] = $array_tmp_uri[2]; //a variavel //Load base require_once("application/application.php"); //Load controller object $application = new Application($array_uri); $application = new Application($array_uri['controller']); ?> application class <?php class Application { var $uri; var $model; function __construct($uri) { $this->uri = $uri; } function loadController($class) { $file = "application/controller/".$this->uri['controller'].".php"; if(!file_exists($file)) die(); require_once($file); $controller = new $class(); if(method_exists($controller, $this->uri['method'])) { $controller->{$this->uri['method']}($this->uri['var']); }else{ $controller->index(); } } function loadView($view,$vars="") { if(is_array($vars) && count($vars) > 0) extract($vars, EXTR_PREFIX_SAME, "wddx"); require_once('view/'.$view.'.php'); } function loadModel($model) { require_once('model/'.$model.'php'); $this->$model = new $model; } } ?> the class that loads views. <?php class Blog extends Application { function __construct() { $this->loadModel('model_blog'); } function index() { $articels = $this->model_blog->select(); $data['articles'] = $articles; $this->loadView('view_blog',$data); } function add($title="") { $data['title'] = $title; $this->loadView('view_blog_add',$data); } } ?> I have hardly any idea of whats going on here. Im just learning how to get the controller to pass link the right view. Thanks
  3. except the title thing. Since the isset $GET['page] failed. Which makes sense since the get page stuff is called later on in the document?
  4. Ahh i saw my error. Used your code now.
  5. ohh yes, I have to use a for loop not just a if statement for the title thing. Now all of a sudden i cant use variables i defined in another function, this is my functons.php which i included into my index: <?php // Navbar top. Use array to add content. function get_mainmenu_array() { $menu = array( "1" => array ( "title" => 'Home', "page" => 'home', "url" => "../content/home.php", "desc_title" => "Web Design Services - Affordable Web And Graphic Design Services | Debes Design" ), "2" => array ( "title" => "Our Services", "page" => 'services', "url" => "../content/services.php", "desc_title" => "Our Services - Static Websites, Dynamic Websites And Content Management Systems | Debes Design" ), "3" => array ( "title" => 'Portfolio', "page" => 'portfolio', "url" => "../content/portfolio.php", "desc_title" => "Our Portfolio - Our Recent Web Design Work | Debes Design" ), "4" => array ( "title" => 'About', "page" => 'about', "url" => "../content/about.php", "desc_title" => "About Us | Debes Design" ), "5" => array ( "title" => 'Contact', "page" => 'contact', "url" => "../content/contact.php", "desc_title" => "Contact Us - Get A Free Quote About Any Design Work | Debes Design" ) ); } function get_mainmenu(){ echo "<ul>"; for ($i = 1; $i <= count($menu); $i++) { echo '<li><a href="index.php?page=' . $menu[$i]['page'] . '">' . $menu[$i]['title'] .'</a></li>'; }; echo "</ul>"; } // dynamic title function html_title() { if(isset($GET['page'])) { $title = 0; $page = $GET['page']; for ($i = 1; $i <= count($menu); $i++) { if($page == $menu[$i]['page'] ) { $title = $i; }else{ echo "Error! No Page"; } } if($title != 0) { echo $menu[$title]['desc_title']; }else{ echo "Error! Title = 0"; } }else{ echo "Error! GET page not set"; } } //Show content works with menu, put in content function get_content() { if(isset($GET['page'])) { if(file_exists("includes/views/" . htmlentities($GET['page'], ENT_QUOTES). ".php")) { include("includes/views/" . htmlentities($_GET['page'], ENT_QUOTES) . ".php"); }else{ include("includes/views/home.php"); } }else{ include("includes/views/home.php"); } } ?> Problem is when the first for loop playes i get the error that the function $menu is undefined. Which is my array at the top. Why? I packed the array into a function and before i just loaded it like so in the title before the second loop: get_mainmenu_array();
  6. since my most of my stuff to do with the $GET['page'] function and the loops variale $i is called later in the document (and has to be) does that mean my function that puts in the title at the top of the html page isnt going to work since almost everything used in it will be defined later? if(isset($GET['page'])) { if($GET['page'] == $menu[$i]['page'] ) { echo $menu[$i]['page']; }else{ die("Error!"); } }else{ die("Error!"); } ?>
  7. ok i made a function containing the script. ahh i seem to have more problems. What I want to create a dynamic html page title which grabs stuff from the array depending on which page is included. So i created this <?php if(isset($GET['page'])) { if($GET['page'] == $menu[$i]['page'] ) { echo $menu[$i]['page']; }else{ echo "Error!"; } }else{ echo "Error!"; } } ?> however the isset already fails since the array is loaded later in the document (I also have no idea if the above script will work). So i figured that i'd give my function some parameters so i can only load the array at the start. But how do i put a large chunk of code in a parameter? ( I cant pack it all into a variable.)
  8. So if I want to put my array and loop into a class along with the second item. Would i do it something like this? <?php class header_menu { var $menu = array( "1" => array ( "title" => 'Home', "page" => 'home', "url" => "../content/home.php" ), "2" => array ( "title" => "Our Services", "page" => 'services', "url" => "../content/services.php" ), "3" => array ( "title" => 'Portfolio', "page" => 'portfolio', "url" => "../content/portfolio.php" ), "4" => array ( "title" => 'About', "page" => 'about', "url" => "../content/about.php" ), "5" => array ( "title" => 'Contact', "page" => 'contact', "url" => "../content/contact.php" ) ); function menu_loop() { for ($i = 1; $i <= count($menu); $i++) { echo '<li><a href="index.php?page=' . $menu[$i]['page'] . '">' . $menu[$i]['title'] .'</a></li>'; }; } function get_main_menu() { echo "<ul>"; echo menu_loop(); echo "</ul>"; } } ?> I dont know how to get further than this. I also dont know where to use any $this-> type stuff. Since all variables are already defined do i still have to inistiate it? or is using a class a bit over the top for this??
  9. I have actually stopped using Dreamweaver for several reasons: 1. Its ridiculously expensive 2. Its not even that great (in relation to price) 3. It doesn't run natively on Linux (probably wont be your problem) Some features like the FTP site synchronization and upload don't work well. When i try to upload sites (10+mb) the thing takes all night and constantly has some issue. On top of all of that the thing is pretty flimsy and isn't even a proper integrated development environment. PHP programming is about as complex as it gets. It has no support and debugging tools for Java, C++ etc. Its way over priced in my opinion. However I have never (and don't) work with WYSIWYG editors etc so I don't know what it offers there. All i ask for is a tool that helps organise the site with a folder explorer thing built in. Has some code hinting (as you type), possibly some site to server sync stuff. And a pleasant interface (since I spend alot of time working with it). Have a look at some open source integrated development environment like eclipse. Eclipse offers plugins for web development (HTML, CSS, PHP, Javascript). It has templates, code hinting etc and is free. However it has no WYSIWYG editor. Heres a list of IDE's http://en.wikipedia.org/wiki/Comparison_of_integrated_development_environments IDE's can be a bit overwhelming since they are mainly for Java, C, Ruby, Perl, PHP etc. But i find eclipse quite easy. They even have a special PHP and web developer edition of it: http://www.eclipse.org/pdt/downloads/ But at the end of the day notepad is just fine too. I started out using it
  10. Cool! I finally get loops now. that opened a lot of php doors for me. BTW: I also had a look at the killerphp OOP PHP tutorial. I just have one question about that and functions in general if i define a function,constant,class in a different file i.e class_lib.php or function_lib.php. If i then call it in another file thats in another folder or on the same level how does it (or does it) know that that function, constant, class was defined in some file in my website folder somewhere?
  11. Thanks. I still have a bit of trouble understanding loops. So the $i is a variable that defines the starting value and by using $i++ makes it go up by one number each time the loop is run. The count function is able to count my array items which are numbers. Is all this correct? But why is it $i <= count($menu)?? why could the above method be a security risk? Is it like the $GET function that presents a security risk because everything has to be put into the url so its possible to manipulate it? also how does the htmlentites know which include file to include??
  12. I have created my menu using a multi dimensional array like so: <?php $menu = array( "1" => array ( "title" => Home, "page" => home, "url" => "../content/home.php" ), "2" => array ( "title" => "Our Services", "page" => services, "url" => "../content/services.php" ), "3" => array ( "title" => Portfolio, "page" => portfolio, "url" => "../content/portfolio.php" ), "4" => array ( "title" => About, "page" => about, "url" => "../content/about.php" ), "5" => array ( "title" => Contact, "page" => contact, "url" => "../content/contact.php" ) ); ?> for this format: <li> <a href='index.php?page='<?php $menu['1'] "page" ?>'></a><?php $menu['1'] "title" ?></li> how do i make it a loop that changes the number next to $menu accordingly? then in my content file i have to make it include the content file <?php if($_GET['page'] == "services") { include("includes/design.html"); }else if($_GET['page'] == "about") { include("includes/graphic.html"); }else if($_GET['page'] == "contact") { include("includes/contact.php"); }else if($_GET['page'] == "portfolio") { include("includes/about.html"); }else{ include("includes/home.php"); } ?> Is there a better way to do it rather than using if , elseif? I know its possible to do something thats just 1 line long but i cant remember it.
  13. Sounds like a good idea. I had a look at the paypal security center and apparently they have alot of buyer and seller dispute assistance etc. So for legal concerns i guess they can help out. I but I think billing in 1/3 is good idea especially if its the first time working with the client. Thanks!
  14. I just got a client who is based overseas. Whats the best method of billing? I like Paypal is that a good idea? Also if I charge upfront, what gives the client piece of mind? How can they protect their initial deposit and be sure that I don't run off with it? on the flip side, if I do some work for a client how can I be sure that I will receive my payment? I obviously don't want to have to charge every 3 minutes. Since a email quote/agreement can be a legally binding contract. Can that help protect me if the client is in a different country? So in essence whats a good quoting and billing strategy in this scenario? Thanks
  • Create New...