I'm trying to build my app with a MVC pattern, to do that I followed a book. In my index.php page I have a button, when I click on that button I want to call my formController to display a form, I'm trying to do that first just showing a simple text with <h1> but it doesnt show any text just a blank page.
Index.php
<?php
//check for errors
error_reporting(E_ALL);
ini_set("display errors",1);
include_once "Models/PageData.php";
$pageData = new PageData();
$pageData->title = "OSeuCondómiono - Gere tudo apartir de uma única plataforma";
$pageData->bootstrap = "<link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'rel='stylesheet'>";
$pageData->jquery = "<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'></script>";
$pageData->bootstrapScript = "<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'></script>";
$pageData->googleApiFont = "<link href='https://fonts.googleapis.com/css?family=Merriweather|Open+Sans|Oswald|Roboto'>";
$pageData->addCss("Css/style.css");
$pageData->content = include_once "Views/home.php";
$formButton = isset($_GET['form-nav']);
if($formButton){
$pageData->content = include_once "Controllers/loginFormCont.php";
}
$page = include_once "Views/layout.php";
echo $page;
?>
loginFormControler
<?php
return "<h1>HIIIII</h1>";
?>
that <h1> doesn't display. I don't know why.
Did you try echo instead of return. Return is better to be used inside a function. Yours is used outside a function.
Related
Im new to Php. I kinda need code to open Links in browser when script is loaded.
heres my code below.
<?php
$links = array_open("https://stackoverflow.com/",
"https://outlook.office.com/",
"https://www.protectedtext.com/",
"https://www.adobe.com/",
"https://www.linkedin.com");
echo $links[array_rand($links)];
?>
Hi change array_open to array
<?php
$links = array("https://stackoverflow.com/", "https://outlook.office.com/", "https://www.protectedtext.com/", "https://www.adobe.com/", "https://www.linkedin.com");
echo $links[array_rand($links)];
?>
And if you want to send the browser to the link you would send a location header like so...
<?php
$links = array("https://stackoverflow.com/", "https://outlook.office.com/", "https://www.protectedtext.com/", "https://www.adobe.com/", "https://www.linkedin.com");
header('Location: ' . $links[array_rand($links)]);
exit;
?>
I have to make some changes on my old website where I'm not using any templating system. I'm loading the content for some pages from a database based on ?page parameter. So I have something like this:
<title>Page title</title>
...
...
...
$page_id = $_GET['page'];
include 'page.php'; //escaping is done in this file
Inside the page.php file I'm actually loading the information about the page. Based on this information I have to change the title of the main page.
I know that this design is not good at all and I wouldn't do this way these days, but to change everything on this website would be too complicated.
Thank you for your ideas.
Try to add php code before title
<html>
<?php
$page_id=$_GET["page"];
include('page.php');
echo "<title>".$page_title."</title>";
?>
<body></body></html>
Inside page.php:
echo '<script>
document.title = "This is the new page title.";
</script>';
How to dynamically change a web page's title?
Enjoy !
<?php
$page_id = $_GET['page'];
if ($page_id == 'first value') {
$title = 'first title';
} else {
$title = 'second title';
}
?>
<title><?php echo $title?></title>
...<?php
include 'page.php'; //escaping is done in this file
I'm uning a php script to get a random news article from a directory and to display it on my website, this works fine, however when I try to recreate it to show something else at random, the new one doesn't work - Here is my code:
<?php
function random_unit($unit_dir = 'sections/units')
{
$units = glob($unit_dir . '/*.php');
$unit = array_rand($units);
return $units[$unit];
}
$unit_1 = random_unit("sections/units");
?>
<?php $unit_1 = file_get_contents( $unit_1 ); ?>
<?php echo $unit_1; ?> // Echo's The Contents Of Selected Random File
Can anyone see where I might have gone wrong?
I have php reading a text file that contains all the names of images in a directory, it then strips the file extension and displays the file name without the .jpg extension as a link to let the user click on then name, what I am looking for is a easy way to have the link that is clicked be transferred to a variable or find a easier solution so the link once it is clicks opens a page that contains the default header and the image they selected without making hundreds of HTML files for each image in the directory.
my code is below I am a newbie at PHP so forgive my lack of knowledge.
thank you in advance. also I would like a apple device to read this so I want to say away from java script.
<html>
<head>
<title>Pictures</title>
</head>
<body>
<p>
<?php
// create an array to set page-level variables
$page = array();
$page['title'] = ' PHP';
/* once the file is imported, the variables set above will become available to it */
// include the page header
include('header.php');
?>
<center>
<?php
// loads page links
$x="0";
// readfile
// set file to read
$file = '\filelist.txt' or die('Could not open file!');
// read file into array
$data = file($file) or die('Could not read file!');
// loop through array and print each line
foreach ($data as $line) {
$page[$x]=$line;
$x++;
}
$x--;
for ($i = 0; $i <= $x; $i++)
{
$str=strlen($page[$i]);
$str=bcsub($str,6);
$strr=substr($page[$i],0,$str);
$link[$i]= "<a href=".$page[$i]."jpg>".$strr."</a>";
echo "<td>".$link[$i]."<br/";
}
?>
</P></center>
<?php
// include the page footer
include('/footer.php');
?>
</body>
</html>
add the filename to the url that you want to use as a landing page, and catch it using $_GET to build the link.
<a href='landingpage.php?file=<?php echo $filename; ?>'><?php echo $filename; ?></a>
Then for the image link on the landing page
<img src='path/to/file/<?php echo $_GET['file'] ?>.jpg' />
I am trying to pull area of a page with AJAX.
In JS I have on click I pass href to PHP;
in PHP(located in tools):
<?php defined('C5_EXECUTE') or die("Access Denied.");
$path = ($_POST['path']);
$page = Page::getByPath($path);
$a = new Area('Main');
$ret = $a->display($page);
echo json_encode($ret);
?>
If I make:
echo json_encode($page);
I receive the page so everything working, But when I try to receive an Area I get this error:
concrete\elements\block_area_header_view.php on line 5
In this File I found this
$c = Page::getCurrentPage();
$areaStyle = $c->getAreaCustomStyleRule($a);
So as I understand $c is null that why I have this error how can I fix this??
This line of code:
$ret = $a->display($page);
...does not do what you think it does. The "display" function does not return the content -- instead it outputs it to the browser. So your json_encode($ret) is just encoding and echo'ing an empty variable.
To capture the displayed content and put it into a variable, you can use php's output buffering feature, like so:
ob_start();
$a->display($page);
$ret = ob_end_clean();