php - Laravel 4 - Use Class Functions inside Views -


i wondering if possible use classes , define functions in controller file , call these methods inside views.

right :

i'm writing normal php functions inluding them inside views :

php file

function viewprofile() {      function getusername() {      $username = auth::user()->username;      return $username;     }      function getname() {      $name = auth::user()->name;      return $name;     }      function getemail() {      $email = auth::user()->email;      return $email;     }  } 

views file :

<?php  include(app_path().'/scripts/profile.php');   viewprofile();  ?>  <td><?php echo getusername() ?></td> 

i want write in classes instead :

public class profile {   public static $username = auth::user()->username; public static $name = auth::user()->]name; public static $email = auth::user()->email;      function getusername() {      return $username;     }      function getname() {      return $name;     }       function getemail() {      return $email;     }   } 

i tried creating controller file , using above code doesn;t seem work - guess controllers can used routing functions only.

is there way use class above , link view , can use methods ?

you use blade want...

in view do...

<div>username: {{ auth::user()->username }}</div> <div>name: {{ auth::user()->name }}</div> <div>email: {{ auth::user()->email }}</div> 

and it, no need classes or else.

tip activate blade add .blade.php extenstion


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -