PHP - Naming Conventions For My Templating
I've been coding my script to PEAR standards, however was wondering what do you recommend for the naming conventions for my templating, I'm currently doing them as how constants would be (uppercase seperated with _ for another word) like:
$xtpl->assign('LATEST_FLASH_TITLE', $latest_flash_title); What do you suggest? Similar TutorialsOkay so I just finished designing a template and I want to begin coding but I want to separate the logic from the template as per suggestions I've received. Now I have the separate files that are ready to be included, but how can I include it so that it updates globally. What I mean is this for example. In my header.php, I have included "style/navbar.php". Now from the root directory that's fine. The problem comes when let's say I'm working inside viewpost.php that is actually inside /style and that file includes header.php which includes style/navbar.php. So now viewpost is looking for style/style.php. How do I make php know where the include files are globally and update that directory for each query? I hope I explained this properly. Hi there, ok I'm stuck... I need to show different headers for certain pages on my website, My template file below calls in all template parts with the 'layout' file being the file which includes a simple html header and menu. How would I go about this? Would I need to create and call on a seperate/second layout file eg. layout2 or can I determine which header shows on certain pages by adding some code to the layout file itself. Any help greatly greatly appreciated. Code: [Select] <?php class Templating extends Model{ function __constructor(){ } function show($center = 'homepage', $right = 'login_box', $left ='left/search_panel', $template = 'layout'){ $data = array( 'right_bar' => $right, 'left' => 'left/search_panel', 'center' => $center, 'left_logged'=>'left/user_panel' ); if ($this->session->userdata('logged_in') == true){ if ($this->session->userdata('admin')){ #$data['right_bar'] = 'right_panel/admin_panel'; $data['left_logged'] = 'right_panel/admin_panel'; }else{ #$data['right_bar'] = 'right_panel/user_panel'; $data['left_logged'] = 'left/user_panel'; //$data['left'] = 'left_panel/user_panel'; } }else{ #$data['right_bar'] = 'right_panel/login_box'; } $this->load->vars($data); $this->load->view($template); } function show_non_live(){ $data = array( 'left' => 'left/search_panel', 'center' => 'center/list_companies', 'left_logged'=>'left/user_panel' ); if ($this->session->userdata('logged_in') == true){ if ($this->session->userdata('admin')){ //$data['right_bar'] = 'right_panel/admin_panel'; $data['left_logged'] = 'right_panel/admin_panel'; }else{ //$data['right_bar'] = 'right_panel/user_panel'; $data['left_logged'] = 'left/user_panel'; } }else{ #$data['right_bar'] = 'right_panel/login_box'; } $template = 'layout'; $this->load->vars($data); $this->load->view($template); } } ?> I currently use HTML strings within my PHP code to display output. And while it might not be best practice, I find it non-restrictive and I can easily add loops, manipulate variables, etc. within my display. However in the interest of having a cleaner code I'm thinking of separating the HTML, without having to use a Template engine like Smarty. I don't care much about replacement patterns to be honest, I don't mind some PHP code withing the HTML, however my biggest issue is loops and having to modify a variable within each loop. Say I have the following example code (Similar to what I'm using right now): Code: [Select] function student_output() { //Retrieve students from array $students_arr = students_info(); $selected_student = $_GET['selected_student']; $output = '<div id="students_container">'; $output .= '<div class="items_list">'; $i = 1; //Loop through students foreach($students_arr as $key=>$value) { if ($selected_student == $key) { $output .= '<div id="student_name_'.$i.'" class="selected">'.$value['student_name'].'</div>'; $output .= '<div id="student_img_'.$i.'" class="selected"><img src="'.$value['student_image'].'" /></div>'; } else { $output .= '<div id="student_name_'.$i.'">'.$value['student_name'].'</div>'; } $i++; } return $output; } What's the best way to represent this in HTML cleanly without having too much PHP code within? Hi guys, What is it called when you have a long paragraph shoretend, With php of course, To make it like haljh;lajbsdg... For example, I have this paragraph: Code: [Select] Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus placerat consequat enim, pretium viverra massa cursus nec. Sed in pharetra magna. Aliquam egestas vehicula mi, sed pellentesque ligula suscipit a. Donec lectus velit, luctus sed lobortis vitae, sollicitudin in sem. Ut facilisis, velit in accumsan porttitor, libero neque molestie leo, ac vulputate eros libero eget mauris. Ut nec justo augue. How to I make it so PHP detects if it is too long and trims it down like: Code: [Select] Lorem ipsum dolor sit amet, consectetur adipiscing elit... If I can find what this is called then I can google it to find it and use it on my site. Thanks in advance! Not sure where to post. For my temporary website, I am trying to figure out the best way to name HTML files. I read that Google gives you points for naming image files after what they are (e.g. "dinosaur.jpeg"). Does the same apply to HTML (and PHP) files? For instance, would there be any benefit as far as SEO goes if a file was named this... a.) "table-20-005-unemployed-workers-by-state.html"
c.) "123456.html" Edited January 14 by SaranacLake I am sure I've asked this or a similar question before, and expect received "personal choice", "it depends" and "most importantly be consistent" as answers. Unfortunately, with so many conflicting recommendations (i.e. Google uses CamelCase, Facebook and Twitter use snake_case, etc), I haven't cemented down my personal choice thus am not as consistent as I should be, so would like to see whether "it depends" might bring consistency. Several potentially influencing factors a I am using Symfony's serializer to serialize and will likely later use it to deserialize. My SQL column names use snake_case. I am okay with exposing some SQL column names in the JSON. While I am using Symfony's serializer, I am not currently using Symfony (I think Symfony promotes CamelCase but am not sure whether this has any impact). I am obviously using PHP.Based on the above, one benefit of using snake_case is I will not need to rename all the serialized names. <property name="some_sql_column" serialized-name="someSqlColumn"/> As such, I am thinking of standardizing on snake_case. Any strong reasons to do differently? This code uploads a file to the server then renames it to the next id number from the database and adds the extension .jpg to the file name. index.php - I need .jpg to be a variable that will append .gif if it's a gif file or .png if it's a png file. Currently, if the file is a .jpg, .gif, or .png, the files are given the extension .jpg. <?php copy($_FILES['banner']['tmp_name']['file'], './banners/'.$photo_id.'.jpg'); ?> _photo.php - I want to replace .jpg in this code with the variable from above. <a href="<?php echo safe_output($photo['web_url']); ?>" target="_blank" class="bannerImg"><img src="banners/<?php echo $photo['id']; ?>.jpg"/></a> |